是否可以根据索引删除数组的内容?如果我有这样的2个数组:
Array1包含15个值,我想获得最后10个值.
在删除元素之前:
array1 == [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
Run Code Online (Sandbox Code Playgroud)
删除元素后:
array1 == [5,6,7,8,9,10,11,12,13,14]
Run Code Online (Sandbox Code Playgroud)
包含15个值的Array2然后我只想获得前10个值.
在删除元素之前:
array2 == [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
Run Code Online (Sandbox Code Playgroud)
删除元素后:
array2 == [0,1,2,3,4,5,6,7,8,9]
Run Code Online (Sandbox Code Playgroud)
但是必须满足条件:
如果数组只包含3个元素则不需要丢弃数组中的元素,以及数组只包含10个元素.但如果数组包含10个以上的元素,则会丢弃多余的元素.
为什么在我的剧本中写下为什么缺少名字.当我包含这样的脚本时,运算符
this.switch = function(){
if (this.status == "enabled")
{
this.disable();
this.stop();
}
else
{
this.enable();
}
}
Run Code Online (Sandbox Code Playgroud)
该脚本旨在将状态从启用转移到禁用
是否可以在JavaScript中访问扩展名为*.txt或*.file的文件?我想在我的函数中调用这个文件?
我在获取索引时遇到问题,如果在数组中有一些相似的单词,但索引位置不同,当我选择其中一个单词时,我得到的索引不是来自单词,而是从中选择相同的单词在以前的位置
例如,我有一句话:
收获是收集的过程
粗体字是我选择的单词..
这是我的代码:
var str = "The Harvest is the process of gathering";
var myArray = str.split ("");
var Select = "the";
Run Code Online (Sandbox Code Playgroud)
我有这样的功能:
function getIndex (arrayItem, item) {
for (var x = 0; x <arrayItem.length; x + +) {
if (arrayItem [x] == item) {
return x;
}
}
return -1;
}
var idx = getIndex (myArray, Select);
Run Code Online (Sandbox Code Playgroud)
如何获得该指数?