js objects
person = {
'name':'john smith'
'age':41
};
console.log(person);
//this will return [object Object]
//use
console.log(JSON.stringify(person));
//insteadvar obj = {
prop1: 5,
obj2: {
prop1: [3, 6, 3],
prop2: 74,
prop3: {
str: "Hello World"
}
}
};
console.log(obj.obj2.prop3.str); //output: "Hello World"let car = {
name: "BMW",
colour: "black",
year: "2020",
owner: {
names = ["Andy" , "Steve" , "Tony" ]
}
};let obj = {
// fields
name:"value",
num: 123,
//methods
foo: function(){}
}var person = {
first_name : "Marty",
last_name : "Mcfly",
born : 1968,
died : 1933,
lovers: ["Jennifer Parker","Baines McFly"]
};// To make an object literal:
const dog = {
name: "Rusty",
breed: "unknown",
isAlive: false,
age: 7
}
// All keys will be turned into strings!
// To retrieve a value:
dog.age; //7
dog["age"]; //7
//updating values
dog.breed = "mutt";
dog["age"] = 8;
Also in JavaScript:
- points in three js
- exceljs read file
- append item to array javascript
- javascript days until end of month
- how do i count the number of occurrences in a string javascript
- assign freemarker expressions to variables
- how to get mouse x and y in javascript
- How to add a new item to an object at a specific position with vanilla JS
- hex string to int javascript
- export default arrow function
- js opposite of includes
- express request body undefined
- how to declare 3d array in javascript
- map over object javascript
- check if js property exists in class
- javascript format price
- laravel json response with error code
- how to comments in json file
- installing node on ec2 instance
- javascript get last word in string
- discord.js create channel
- jquery get data attribute
- axios get array of urls
- how to see if a web site is useing react