javascript - Trouble reformatting JSON into an array for use in AngularJs -


js has built-in parse function using: json.parse. it's reformatting i'm having trouble wrapping head around. eg if want fetch stars nasa api json. gives me massive list of stars, 1 entry looking this:

{     "absmag": 4.85,      "appmag": -26.72,      "colorb_v": 0.65,      "created_at": "2014-11-08t07:30:49.614z",      "dcalc": 0.0,      "distly": 0.0,      "hipnum": 0.0,      "id": 1,      "label": "sun",      "lum": 0.8913,      "plx": 0.0,      "plxerr": 0.0,      "speed": 0.0,      "texnum": 1.0,      "updated_at": "2014-11-08t07:30:49.614z",      "vx": 0.0,      "vy": 0.0,      "vz": 0.0,      "x": 0.0,      "y": 0.0,      "z": 0.0 } 

i strip out "label" value searching:

window.database.foreach(function(el) {             var starnamearray = el.label;         }) 

which gives me plain list of star labels. need convert list form:

[ 'thing1', 'thing2', 'thing3' ] 

i attempt use this:

console.log("'" + starnamearray.join("','") + "'"); 

but error: "uncaught typeerror: starnamearray.join not function"

any idea why? making stupid mistake somewhere along line here?

var starnamearray = []; window.database.foreach(function(el) {    starnamearray.push(el.label); }); console.log(starnamearray.join(",")); 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -