如何在索引从1开始的javascript中创建数组 [英] How do I create an array in javascript whose index starts from 1
本文介绍了如何在索引从1开始的javascript中创建数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
默认情况下,每个javascript数组的索引从0开始。我想创建一个索引从1开始的数组。
我知道,必须非常简单... thnx for ur help
By default index of every javascript array starts from 0. I want to create an array whose index starts from 1. I know, must be very trivial...thnx for ur help
推荐答案
这不是微不足道的。不可能。您可以做的最好的事情是使用从1开始的数字属性创建一个对象,但这不是一回事。
It isn't trivial. It's impossible. The best you could do is create an object using numeric properties starting at 1 but that's not the same thing.
为什么要让它从1开始呢?要么:
Why exactly do you want it to start at 1? Either:
-
从0开始并根据需要调整指数;或
Start at 0 and adjust your indices as necessary; or
从0开始,忽略索引0(即只使用索引1及以上)。
Start at 0 and just ignore index 0 (ie only use indices 1 and up).
这篇关于如何在索引从1开始的javascript中创建数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文