【发布时间】:2020-03-01 06:41:19
【问题描述】:
我有一个数组缺少某些索引的值,您能否建议用 null 或 0 填充它们的最佳方法,我在 lodash 中尝试了可能的方法,但似乎没有任何工作。
按照下面的问题,没有任何帮助
Filling the missing index and filling its value with 0
fill multiple missing values with series based on index values
Python - filling a list of tuples with zeros in places of missing indexes
我的数组的console.log 输出低于输出
[ 5289, <1 empty item>, 20460, 10860, '189', 'D2989', <1 empty item>, <2 empty items>, '-' ]
我想填写的地方
[ 5289, null, 20460, 10860, '189', 'D2989', null, null,null, '-' ]
【问题讨论】:
-
“某些索引的缺失值”,这是否意味着它们是“未定义”/“空”?还是它们是“空的”插槽?
-
为什么要查找 Python 解决方案?稀疏数组将在未初始化的索引处未定义。实际问题是什么?没有任何代码或上下文,很难知道你真正想要什么。
-
Javascript 中不能有“缺失”的数组索引。索引总是从 0 开始,最大有效索引将由数组的长度决定。您想在数组末尾添加更多元素,即填充其长度吗?
-
请分享您的数组变量的最小示例。
标签: javascript arrays lodash