“Buscar índice en Array JavaScript” Código de respuesta

Cómo encontrar el índice de un valor en una matriz en JavaScript

var list = ["apple","banana","orange"]

var index_of_apple = list.indexOf("apple") // 0
Clumsy Crayfish

React Array Find Índice

//The findIndex() method returns the index of the first element 
//in the array that satisfies the provided testing function.
//Otherwise, it returns -1, indicating that no element passed the test.
const array1 = [5, 12, 8, 130, 44];

const isLargeNumber = (element) => element > 13;

console.log(array1.findIndex(isLargeNumber));
// expected output: 3
Skoll

JavaScript FindIndex

const array1 = [5, 12, 8, 130, 44];
const search = element => element > 13;
console.log(array1.findIndex(search));
// expected output: 3

const array2 = [
  { id: 1, dev: false },
  { id: 2, dev: false },
  { id: 3, dev: true }
];
const search = obj => obj.dev === true;
console.log(array2.findIndex(search));
// expected output: 2
SmokeFrog

Índice de valor en la matriz

// for dictionary case use findIndex 
var imageList = [
   {value: 100},
   {value: 200},
   {value: 300},
   {value: 400},
   {value: 500}
];
var index = imageList.findIndex(img => img.value === 200);
Hesterian

índice de javascript

//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
Grepper

Buscar índice en Array JavaScript

// find index of array in javascript
const number = [1,6,2,8,1,0,4,2,7,5,4,1];
const index = number.findIndex(item => item === 8);
console.log(index)
Chetan Nada

Respuestas similares a “Buscar índice en Array JavaScript”

Preguntas similares a “Buscar índice en Array JavaScript”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código