Answers for "indexof js object"

9

javascript indexOf object value in array

// Get index of object with specific value in array
const needle = 3; // needle
const haystack = [{ id: 1 }, { id: 2 }, { id: 3 }]; // haystack
const index = haystack.findIndex(item => item.id === needle);
Posted by: Guest on September-23-2020
3

using index of on array of objects

arr = [{x: "a", y: 1}, {x: "something", y: 2}]
arr.findIndex(obj => obj.x === "a" && obj.y === 1);
Posted by: Guest on June-10-2020
50

javascript indexof

//indexOf getting index of array element, returns -1 if not found
var colors=["red","green","blue"];
var pos=colors.indexOf("blue");//2

//indexOf getting index of sub string, returns -1 if not found
var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");//9
Posted by: Guest on June-27-2019
9

indexof javascript

Array.indexOf(searchElement, fromIndex)
Posted by: Guest on January-14-2020
0

JS, indexOf();

function quickCheck(arr, elem) {
  return arr.indexOf(elem) != -1;
}
console.log(quickCheck(["squash", "onions", "shallots"], "mushrooms"));
Posted by: Guest on May-26-2021
1

indexof javascript

arr.indexOf(searchElement[, fromIndex])
Posted by: Guest on January-23-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language