So i have this kind of array from json
data : [{
    article_categories : {
        id : "xxx",
        name : "xxx"
    },
    article : "xxx",
    publisher : "xxx"
}]
I wanted to create another multi dimension array for those array and i want to keep the fields name (the name "article","publisher" and so on in the array)  with value in there but i have no idea to get fields name
And i also want to do some conditional if to only include some fields into my new array by checking from this array
thead: [
    { key: "article"},
    { key: "article_categories.name"},
    .....
]
so i the end there will be array like this
newArray: [
 {article:"xxx",publisher: "xxx",article_categories.name:"xxx"},
 {article:"xxx",publisher: "xxx",article_categories.name:"xxx"}
 ....
]
how to do that? i tried
thead.forEach(function(column){
  data.forEach(function(key,value){
      if(column.key == key){
         newArray[key] = value
      }
  })
})
but it just not working....
 
     
     
    