Search
 
SCRIPT & CODE EXAMPLE
 

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"
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript get page args 
Javascript :: add decimals javascript 
Javascript :: use await in for each 
Javascript :: location.reload() js 
Javascript :: object methods in javascript 
Javascript :: c# razor for loop javascript 
Javascript :: convert form data request to json laravel 
Javascript :: document fragment 
Javascript :: extract content from string html 
Javascript :: add 1 year to given date in javascript 
Javascript :: await loop javascript 
Javascript :: execute command js 
Javascript :: regex check if number is greater than 
Javascript :: run node js 
Javascript :: input events 
Javascript :: javascript equivalent of CTRL+F5 
Javascript :: latitude longitude to km javascript 
Javascript :: async function in javascript 
Javascript :: get url in javascript 
Javascript :: closures in javascript 
Javascript :: flutter webview enable javascript 
Javascript :: js select keys from object 
Javascript :: pm2 logs on same console 
Javascript :: patterns in javascript 
Javascript :: react chrome extension 
Javascript :: crypt a string jquery 
Javascript :: javascript primitive data types 
Javascript :: set selected option jquery 
Javascript :: jquery select input 
Javascript :: js store regex in variable and combine 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =