Search code examples
javascriptlistpropertiesincrement

How iterate specific list's property


Im new on JS and i already push all content from this on my arraylist MyList but i wanted to get all title property to push on my titleList

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

Solution

  • 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)
    });