Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript filter map array of objects

let flights = [
  { flightid: 11, aerodrome: ["aaa", "bbb"] },
  { flightid: 22, aerodrome: ["aaa", "ccc"] },
  { flightid: 33, aerodrome: ["ddd"] },
  { flightid: 44, aerodrome: ["ddd", "bbb"] }
];

let aerodromeAAA = flights.filter((f) => f.aerodrome.includes("aaa"));

console.log(
  `Total of ${flights.length} flights, flights with aerodrome='bbb' is ${aerodromeAAA.length}`
);

// "Total of 4 flights, flights with aerodrome='bbb' is 2"


console.log(`AAA aerodromes flight IDs: ${aerodromeAAA.map((a) => a.flightid).join(", ")}`);

// "AAA aerodromes flight IDs: 11, 22"
 
PREVIOUS NEXT
Tagged: #javascript #filter #map #array #objects
ADD COMMENT
Topic
Name
9+2 =