There is some coding in this discussion. Feel free to write them in a REPL or in the comments below.
- How is an object different from an array?
- How does
const
work with objects? - Explain the difference between bracket syntax and dot syntax. Give an example of something that works with bracket syntax but not dot syntax. Give an example of something that works with dot syntax but not bracket syntax.
- What are computed properties? Write an example code.
- What is the difference between
Object.keys
andObject.entries
? Write example code using both of them. - How do we get only the values of an object?
We can't access an item by index as in an array.
We can’t use push while adding property.
We access properties of an object with dot sign.
Arrays contain values, while objects contain property and its value.
we can change inside of an object (delete, push etc) but we can't change the object itself, which means if I declare an object called “eg: person” I can not declare another object called person, while I can change the content of this object.
We can't use dot for arrays; dot is used for objects properties. However for example I have an array that consists
[1,2,3,4] then we can say array.name = "zisan". After printing this array it will give [1,2,3,4], when we
want to console log array.name it will give zisan. For the brackets, if we want to print properties of an object
we should use string inside brackets, but if we want to print items of an array we should have index inside brackets.
Computed properties allow you to dynamically choose what property in your object gets updated. It’s important to give your input element a name attribute, and name attribute that you specify should match the property that you wish to update within the object.
E.g.
“
// Computed property
let i = 0
let a = {
['foo' + ++i]: i,
['foo' + ++i]: i,
['foo' + ++i]: i
}
console.log(a.foo1) // 1
console.log(a.foo2) // 2
console.log(a.foo3) // 3
”
object.key is the value for attribute , while object.entire is a pair of attribute and it’s value
let object = {name: "zisan", lastname:"uzum", age:22}
undefined
Object.keys(object)
Array(3) [ "name", "lastname", "age" ]
Object.entries(object)
Array(3) [ (2) […], (2) […], (2) […] ]
0: Array [ "name", "zisan" ]
1: Array [ "lastname", "uzum" ]
2: Array [ "age", 22 ]
length: 3
we can call the object with its name console.log(Object.values(obj))
Group Names: Kemal Davut , Zisan Uzum, Rasha Bsirini, Abdelrahman Mostafa