javascript - Return Array Element inside of an Object array -
i have code below. want access array(named link1 , link2) elements inside of obj array.
$(function() { var storage = chrome.storage.local; storage.clear(); var link1 = 'mylinks1'; var link2 = 'mylinks2'; var obj= {}; obj[link1] = ['www.google.com', 'yahoo.com', 'www.msn.com']; obj[link2] = ['www.microsoft.com', 'live.com', 'www.espn.com']; storage.set(obj); storage.get(null,function(result){ //returns obj array of links inside console.log(result); // returns array of obj doesn't contain array of links inside. console.log(object.keys(result)); }); });
edit: want able access links such www.google.com
thanks
you should able keys , array values in result writing following loop
object.keys(obj).foreach(function(key) { console.log(key, obj[key]); (var in obj[key]) console.log(obj[key][i]); });
output:
mylinks1 ["www.google.com", "yahoo.com", "www.msn.com"]
www.google.com
yahoo.com
www.msn.com
mylinks2 ["www.microsoft.com", "live.com", "www.espn.com"]
www.microsoft.com
live.com
www.espn.com
Comments
Post a Comment