Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Nested Array Filter

function display_message() {
  let arrayOfElements = [{
    "name": "a",
    "subElements": [{
      "surname": 1
    }, {
      "surname": 2
    }]
  }, {
    "name": "b",
    "subElements": [{
      "surname": 3
    }, {
      "surname": 1
    }]
  }, {
    "name": "c",
    "subElements": [{
      "surname": 2
    }, {
      "surname": 5
    }]
  }];
  // console.log(arrayOfElements);
var surname = 1;
  let filteredArray = arrayOfElements.filter((element) => element.subElements.some((subElement) => subElement.surname === surname));

  for(var data in filteredArray){
    filteredArray[data].subElements = {"surname": surname};
    }
  console.log(filteredArray);

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert json to table in sql server 
Javascript :: firebase auth update current user 
Javascript :: new Date() get speicifc hours min sec 
Javascript :: Ways to iterate array in js 
Javascript :: img src to file javascript 
Javascript :: polyfill for bind 
Javascript :: radio button getelementsbyname 
Javascript :: disable button 
Javascript :: drupal 9 get nid from node 
Javascript :: redux dispatch no connect 
Javascript :: json minecraft 
Javascript :: selectize.js setvalue 
Javascript :: change property in array of objects javascript 
Javascript :: o que é jsonm 
Javascript :: how to remove an object from an array javascript 
Javascript :: javascript random number not decimal 
Javascript :: get element in javascript 
Javascript :: mapdispatchtoprops 
Javascript :: change href javascript 
Javascript :: jqery first img src 
Javascript :: css on javascript 
Javascript :: react native scrollbar position issue 
Javascript :: js indexof second occurrence 
Javascript :: add two numbers in javascript 
Javascript :: requestanimationframe 
Javascript :: not disabled jquery 
Javascript :: round innerhtml up 
Javascript :: removeeventlistener click 
Javascript :: how to check if user has installed pwa 
Javascript :: request entity too large express 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =