需要仅重置Javascript数组的索引 [英] Need to reset just the indexes of a Javascript array

查看:135
本文介绍了需要仅重置Javascript数组的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回数组的for循环:
return

I have a for loop which returns an array : return

1st loop:
arr[0]
arr[1]
arr[2]
arr[3] Here length that i get is 4 (Not a problem)

返回

2nd loop
arr[4]
arr[5]
arr[6]
arr[7] 
arr[8] 

我得到的长度是9.返回

Here length that i get is 9. return

我想要的是指数的实际数量,即我需要它是5.我怎么能这样做...有没有一种方法,当我每次从0开始进入每个循环,以便我在所有循环中获得适当的长度?

What i want here is the actual count of the indexes i.e i need it to be 5. How can i do this..And is there a way that when i enter each loop everytime it starts from 0 so that i get proper length in all the loops?

推荐答案

这很容易使用Array.filter本地完成:

This is easily done natively using Array.filter:

resetArr = orgArr.filter(function(){return true;});

这篇关于需要仅重置Javascript数组的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆