JavaScript数组计数和删除零
我有一个数组 let test = [0,0,0,0,0,0,0,0,0,0,3,4,5,6,3,0, 0,0,0,4,6,7]
我需要从起点计算零的数量,在本例中为“9”,直到值 3
下一步想要只删除前九个条目。数组其余部分中的剩余零必须保留。
预期结果
计数 = 9 让测试= [3,4,5,6,3,0,0,0,0,4,6,7]
I have an Array let test = [0,0,0,0,0,0,0,0,0,0,3,4,5,6,3,0,0,0,0,4,6,7]
I need to count the amount of zero's from the starting point in this case "9" upto value 3
Next want to only delete the first nine entries . The remaining zero's in the rest of the array must remain.
Expected Result
Count = 9
Let Test = [3,4,5,6,3,0,0,0,0,4,6,7]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,示例的结果应该是
Count = 10
,因为0
有 10 个。我想您想定义一个函数来获取结果。那可以是:
First of all, the result of your example should be
Count = 10
because there are 10 of0
.I suppose you want to define a function to get the result. That can be:
请尝试以下代码:
谢谢
Please try the following code :
Thanks