Ale*_*lex 156 javascript arrays push
我需要关于这个问题的帮助 - "JavaScript push();方法的反义词是什么?"
就像说我有一个阵列 -
var exampleArray = ['remove'];
Run Code Online (Sandbox Code Playgroud)
我想要push();这个词'keep'-
exampleArray.push('keep');
Run Code Online (Sandbox Code Playgroud)
如何'remove'从数组中删除字符串?
Ama*_*dan 133
push()最后添加; pop()从最后删除.
unshift()加到前面; shift()从前面删除.
splice() 可以随心所欲地做任何事情.
Tra*_*ohl 113
好吧,你有点问过两个问题.push()(题为标题)的反面是pop().
var exampleArray = ['myName'];
exampleArray.push('hi');
console.log(exampleArray);
exampleArray.pop();
console.log(exampleArray);Run Code Online (Sandbox Code Playgroud)
pop()将删除最后一个元素exampleArray并返回该元素("hi"),但它不会从数组中删除字符串"myName",因为"myName"不是最后一个元素.
var exampleArray = ['myName'];
exampleArray.push('hi');
console.log(exampleArray);
exampleArray.shift();
console.log(exampleArray);Run Code Online (Sandbox Code Playgroud)
var exampleArray = ['myName'];
exampleArray.push('hi');
console.log(exampleArray);
exampleArray.splice(0, 1);
console.log(exampleArray);Run Code Online (Sandbox Code Playgroud)
有关更多数组方法,请参阅:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Mutator_methods
| 归档时间: |
|
| 查看次数: |
51750 次 |
| 最近记录: |