Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中找到多个对象的索引?_Javascript_Reactjs_Indexof - Fatal编程技术网

如何在javascript中找到多个对象的索引?

如何在javascript中找到多个对象的索引?,javascript,reactjs,indexof,Javascript,Reactjs,Indexof,这里我有questionDetails.questions命名数组在数组中我有13个对象,所以我想在javascript中找到所有13个对象的索引,这是怎么可能的 如果您想返回单独数组中的任何字段,您可以使用map例如i returnid const questionIds = questionDetails.questions.map(question => question.id); 或者,如果您想在问题数组中查找任何id,或者只返回该部分,则可以使用过滤器,例如 const que

这里我有
questionDetails.questions
命名数组在数组中我有13个对象,所以我想在javascript中找到所有13个对象的索引,这是怎么可能的


如果您想返回单独数组中的任何字段,您可以使用
map
例如i return
id

const questionIds = questionDetails.questions.map(question => question.id);
或者,如果您想在问题数组中查找任何id,或者只返回该部分,则可以使用
过滤器
,例如

const question = questionDetails.questions.filter(question => question.id === 1);
您可以使用id查找


index=questionDetails.questions.map(函数(e){returne e.id;}).indexOf('35')

您只需映射数组并获取索引,如下所示:

questionDetails.questions.map(function(item, index){ console.log(index) })

希望这有帮助:)

您有一个数组,您将有数组长度(array.length),我想您知道数组索引将从0开始到
长度-1

神奇的功能:

function getIndexOfArray(arr) {
  let indexes = [];
  for (let i = 0; i < arr.length; i++) {
    indexes.push(i);
  }
  return indexes;
}

let myIndexes = getIndexOfArray(questionDetails.questions);

console.log(myIndexes); // [0,1,2,3,4,5,6,7,8,9,10,11,12]
// :|
函数getIndexOfArray(arr){ 让索引=[]; for(设i=0;i
我想这就是你想要的。(??)

我想找到javascript中所有十三个对象的索引!!你的意思是id吗?没有索引我有allready id我想要这个对象的索引我不想找到id我想找到数组0,1,2,3,4,5,6,7,8,9,10,11,12的索引这…我应该在35的位置放什么,因为35是静态的,你必须使用对象的一个键来找到它的索引,否则怎么可能呢?如果你想找到所有的,只要使用该逻辑在循环中,并逐个提供id