let object = {
name : "Petya",
age : 15
};
// another way
let object = new Object();
object["name"] = "Petya";
object["age"] = 15;
// old way
var object = new Object()
object.name = "Petya";
object.age = 15;
// 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;
1) Object Literal
const obj = {
name: "Ram",
age: "20"
}
2) Constructor Function or ES6- Class
const a = new Person("Ram", "25") //given Person is an existing function or class
3) Object.create method
const ram = Object.create(Person); //given person is an existing object
[object Object]
/*
This means that your programming interpreter doesn't support showing
JSON parsers somewhere, and has resorted to the default object representation
behavior (see below).
Behavior: [object CLASS]
Since it's an object, well: [object Object]
This is most commonly seen in a depraved, deranged state in objects
ingrained into text. We still haven't really devised a prophecy
about why it still happens in some places. Either JavaScript likes to
be vexing by being "open" aka adding unnecessary steps, or JavaScript
has something like security issues related to its code/some other
predicament retaining and pertaining.
*/
/*
An object is made of key value pairs. Keys can be strings
(which don't require quotes), array with a string, or symbols. Values can be arrays,
objects, numbers etc
*/
let testSymbol = Symbol('item number 3')
const obj = {
item1: 1,
"item number 2": 2,
testSymbol: 3,
['a']: 4
}
// Another way of creating an object:
const obj = new Object();
obj.name = 'John'
// To access values, you can use dot notation or bracket notation.
// Both do the same thing, bracket notion is useful for multispace keys,
// keys with dashes, or accessing values using variables
> obj.item1
> obj['item number 2']
> let b = 'item1'
obj[b]
// The following would NOT work and would return undefined:
obj.b
// Checking exsistence of keys in object:
obj.toString ----- checks values of object and whatever object inherits from
> returns true
obj.hasOwnProperty('toString') ----- checks values of object only. Do this instead of checking like: (obj.name !== undefined)
> returns false
// Short hand key assignment:
const name = 'John'
const obj2 = {
// this is short hand that automatically sets the key to be 'name',
// and it's value to be 'John'
name,
}
// Constructor objects:
function Obj(name, age){
this.name = name
this.age = age
}
const person = new Obj('john', 1)
// adding functions, couple ways:
const obj = {
name: 'Mike',
number: 4421,
sayHi: () => console.log('hi'),
sayBye() {
console.log('say bye')
},
// getter function to get values from object. Has different usecases, but the same as doing obj.number
get getNumber(){
return this.number
}
// setter function to set values in object. Has different usecases, but the same as doing obj.number = 152
set setNumber(num){
this.number = num
}
}
obj.sayHi()
obj.sayBye()
obj.getNumber //Note how it's being accessed like a standard property, and not a function
obj.setNumber //Note how it's being accessed like a standard property, and not a function
Remove the constraint on object before deleting your field
The constraint is typically created automatically by the DBMS (SQL Server).
To see the constraint associated with the table
in SSMS -> expand the table attributes in Object explorer -> category Constraints -> right click on constraint and click delete
{
"error": {
"code": 403,
"message": "YouTube Data API v3 has not been used in project 300294518029 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=300294518029 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"errors": [
{
"message": "YouTube Data API v3 has not been used in project 300294518029 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=300294518029 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"domain": "usageLimits",
"reason": "accessNotConfigured",
"extendedHelp": "https://console.developers.google.com"
}
],
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developers console API activation",
"url": "https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=300294518029"
}
]
},
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "SERVICE_DISABLED",
"domain": "googleapis.com",
"metadata": {
"service": "youtube.googleapis.com",
"consumer": "projects/300294518029"
}
}
]
}
}
const person = {
firstName: 'John',
age: 30,
greet() {//method
console.log('Hi, I am ' + this.name);
},
age(){//method
console.log('I am ' + this.age + ' years old');
}
}
person.lastName = 'Doe';//add property to object
console.log(person.lastName);// output: Doe
// Calling a method
person.greet();// output: Hi, I am Doe
person.age();// output: I am 30 years old
//// Write a function that takes an array of objects (courses) and returns object of 2 new arrays // first one is containing the names of all of the courses in the data set. // second one is containing the names of all the students
const getInfo = (arr) => {
let coursesName = [];
let studentsName = [];
// write your code here
return { coursesName, studentsName };
};
//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)