Home > Net >  How iterate specific list's property
How iterate specific list's property

Time:03-31

Im new on JS and i already push all content from enter image description here

I don't know if i need to use incrementation get all title, so i found this exemple which seems logical to me :

...
const MyList = []
MyList.push(json_response)

const titleList = []

Object.keys(MyList).forEach(key => {
   console.log(key, obj[title]);
   titleList.push([title])
 });

and i found this:

 ReferenceError: Cannot access 'title' before initialization
    at /Users/mac/Desktop/My_test/index.js:55:28
    at Array.map (<anonymous>)
    at /Users/mac/Desktop/My_test/index.js:42:33

CodePudding user response:

title is not defined at this point provided json_response has data try this...

const MyList    = []
const titleList = []

MyList.push(json_response)

MyList.forEach(item => {
  console.log(item);
  titleList.push(item.title)
});

  • Related