推对面(); [英] Opposite of push();

查看:132
本文介绍了推对面();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助解决这个问题 - 什么是JavaScript相反推(); 办法

I need help on this problem - 'What is the opposite of the JavaScript push(); method?'

好比说我有一个阵列 - VAR exampleArray = ['MYNAME'];

Like say I had a array - var exampleArray = ['myName'];

我想推(); 'HI' - exampleArray。推('你好');

如何删除字符串MYNAME从数组?

How do I delete the string 'myName' from the array?

推荐答案

好,你有种问了两个问题。 的反面推()(因为这个问题的标题)为 POP()

Well, you've kind of asked two questions. The opposite of push() (as the question is titled) is pop().

exampleArray.pop();

POP() exampleArray 删除最后一个元素并返回该元素 - 在你的情况下,字符串'喜' - 但它不会删除从数组字符串'MYNAME',因为MYNAME'不是最后一个元素。对于您需要拼接()移()

pop() will remove the last element from exampleArray and return that element -- in your case, the string 'hi' -- but it will not "delete the string 'myName' from the array" because 'myName' is not the last element. For that you need splice() or shift():

exampleArray.splice(0,1);

exampleArray.shift();

有关更多信息,请参见:<一href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Mutator_methods\">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Mutator_methods

For more info, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Mutator_methods

这篇关于推对面();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆