gpt4 book ai didi

Javascript shift() unshift() 助记符?

转载 作者:行者123 更新时间:2023-12-03 03:49:04 26 4
gpt4 key购买 nike

我很难记住什么 Array.shift()Array.unshift()做。

几年后,当我需要使用其中之一时,我仍然会不时查看引用资料。谁能解释为什么选择这些名字以及如何记住哪个名字做什么?

我对 Array.push() 没有这样的问题和Array.pop()

最佳答案

据我所知。

移位命令来自二进制移位[1]。例如。

    001100
0 < 011000 // when you shift left
|
Yay!

我觉得很简单,就像你从后面推它一样。所以这对我来说很有意义。

unshift与shift相反。

    001100
1 > 001100 // they called it unshift
1001100
|
Yay!

就是这样,希望对你有帮助!

[1] http://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts

关于Javascript shift() unshift() 助记符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19107752/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com