I filled up an array with some objects like this and printing it out with JSON.stringifty(obj, null, '\t');
gives me output like this:
[
{
"title": "here's the title"
},
{
"description": "this is a description"
}
]
now I am trying to get the data back from this array with objects inside. Using array.map like this:
var title = objArray.map(function(a) {return a.title;});
when I do:
console.log(title); //the output looks like this
,here's the title,,,
If I manually reach into the array like this
console.log(results[0]['title']); //the output is well formatted
here's the title
why is that and how can I get the map function to not add those additional commas to my returned value?
map()
returns an array. If you try to output (e.g. viaconsole.log()
) an array, it is first implicitly joined, as though you'd donearray.join()
. The commas are a result of that implicit join. – Utkanos Jul 27 at 18:10