Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="example of finding an object in an array by a given key,value"/>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
const labels = [
    { id: 1, name:"string 1", value:"this", other: "that" },
    { id: 2, name:"string 2", value:"this", other: "that" },
    { id: 3, name:"string 2", value:"this", other: "that" },
];
const selected = [1,3];
const searchInArray = (array, prop, value) => array.filter(element => element[prop] === value);
const result = selected.flatMap(id => searchInArray(labels, 'id', id));
console.clear();
console.log(result);
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
theprivilegespro
0viewers