0

is says i is undefined in line url: data.url[i]??

  $scope.data = [{
    "url":"http://www.google.com"
  },
  {
        "url":"http://www.bing.com"
  },{
        "url":"http://www.yahoo.com"
  }];

            angular.forEach($scope.data, function(data){
                //var links = data.url;
  console.log(data);
  //I need array to be use in
                chrome.tabs.create({
                    url: data.url[i]
                });

        });

1 Answer 1

1

You don't need i at all. data already refers to the individual item.

angular.forEach($scope.data, function(data){
    chrome.tabs.create({
        url: data.url
    });
});

Although to avoid confusion, you might want to use a parameter name other than data in the forEach function, since your $scope variable is also named data.

angular.forEach($scope.data, function(item){
    chrome.tabs.create({
        url: item.url
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

I see thanks! I read it wrongly.. It worked but you u know how to focus on the first link? so far I focus on yahoo coz it is the last link, I want window focus on google.com which is the firstly opened tab. Any idea?
Sorry, I don't know anything about how you're creating tabs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.