Created
August 30, 2017 12:29
-
-
Save afrontend/82b60417519a6ef4982adedbdb989649 to your computer and use it in GitHub Desktop.
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 = {} | |
b = new Object() | |
typeof(a) | |
typeof(b) | |
a | |
b | |
a['name'] = 'apple' | |
a['color'] = 'red' | |
a | |
Object.entries(a) | |
Object.keys(a) | |
Object.values(a) | |
Array.isArray(Object.entries(a)) | |
Array.isArray(Object.keys(a)) | |
Array.isArray(Object.values(a)) | |
'name' in a | |
a['name'] === 'apple' | |
Object.keys(a).indexOf('name') !== -1 | |
Object.values(a).indexOf('apple') !== -1 | |
var val, | |
property; | |
for (property in a) { | |
if (a.hasOwnProperty(property)) { | |
val = a[property]; | |
console.log(property + ': ' + val); | |
} | |
} |
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 = {} | |
b = dict() | |
type(a) | |
type(b) | |
a | |
b | |
a['name'] = 'apple' | |
a['color'] = 'red' | |
a | |
list(a.items()) | |
list(a.keys()) | |
list(a.values()) | |
type(a.items()) | |
type(a.keys()) | |
type(a.values()) | |
'name' in a | |
('name', 'apple') in a.items() | |
'name' in a.keys() | |
'apple' in a.values() | |
for key, value in a.items(): | |
print(key + ': ' + value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://agvim.wordpress.com/2017/08/30/python-dictionary-vs-javascript-object/