Created
August 23, 2017 13:00
-
-
Save afrontend/acb1269ddcb322033b0cd42d91f8af23 to your computer and use it in GitHub Desktop.
Python list method vs. JavaScript Array method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1] | |
a | |
a.push(2) | |
a | |
a[a.length] = 9 | |
a | |
a = a.concat([4, 5]) | |
a | |
a.splice(a.length, 0, 5, 6, 7) | |
a | |
a.splice(1, 0, 0) | |
a | |
a.splice(a.length - 1, 0, 8) | |
a | |
a.splice(a.indexOf(9), 1) | |
a | |
a.pop() | |
a | |
((ary, value) => { return ary.reduce((count, item) => {return item == value ? count + 1 : count}, 0) })(a, 5); | |
a.indexOf(5) | |
a | |
a.reverse() | |
a | |
a.sort() | |
a | |
b = a.slice() | |
b | |
a.length = 0; | |
a | |
a = b | |
a | |
a.splice(0, a.length) | |
a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1] | |
a | |
a.append(2) | |
a | |
a[len(a):] = [9] | |
a | |
a.extend(range(4, 6)) | |
a | |
a[len(a):] = range(5, 8) | |
a | |
a.insert(1, 0) | |
a | |
a.insert(len(a) - 1, 8) | |
a | |
a.remove(9) | |
a | |
a.pop() | |
a | |
print(a.count(5)) | |
a.index(5) | |
a | |
a.reverse() | |
a | |
a.sort() | |
a | |
b = a.copy() | |
b | |
a.clear() | |
a | |
a = b | |
a | |
del a[:] | |
a | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://agvim.wordpress.com/2017/08/22/python-list-vs-javascript-array/