Obektlar judaham ko'p qiymatlarni o'z ichiga olishi mumkin va malumotlar uchun kontainer vazifasini bajaradi, obektlarni xosil qilishning birnechta usullari mavjud keng qo'llaniladigan va foydalanishga qulay usul bu litiralusul.!
obekt konstruktor
usuli.!
const person=new Object();
person.fName="Alexander";
person.lName="Noah";
person.face='have round face';
person.weight='120kg';
person.height='180sm';
person.job='BodyBuilder';
console.log(person);
// natija - {fName: 'Alexander', lName: 'Noah', face: 'have round face', weight: '120kg', height: '180sm', job: 'BodyBuilder'}
obekt litiral
usuli.!
const car={
type:"BMW",
price:"50000$",
wight:"1500kg",
speed:"300km/h"
};
console.log(car);
// natija - {type: 'BMW', price: '50000$', wight: '1500kg', speed: '300km/h'}
Obektlarning xususiyatlari.!!!
- Obektning xususiyatiga kirish.!
obektning xususiyatiga kirish sintaksisi:
objectName.property
objectName["property"]
const car={
type:"BMW",
price:"50000$",
wight:"1500kg",
speed:"300km/h"
};
let result1=car.type;
console.log(result1);
// natija - BMW
let result2=car["price"];
console.log(result2);
//natija - 50000$
yangi xususiyat qo'shish
sintaksis: objectName.key="newValue"
const person={
fName:"samandar",
lName:"hodiev",
job:"programmer"
};
console.log(person);
// natija - {fName: 'samandar', lName: 'hodiev', job: 'programmer'}
// add new property
person.age=21;
console.log(person);
// natija - {fName: 'samandar', lName: 'hodiev', job: 'programmer', age: 21}
Xususiyatlarni o'chirish
sintaksis:delete objectName.key
const person={
fName:"samandar",
lName:"hodiev",
job:"programmer"
};
console.log(person);
// natija - {fName: 'samandar', lName: 'hodiev', job: 'programmer'}
// delete property
delete person.job;
console.log(person);
// {fName: 'samandar', lName: 'hodiev'}
Top comments (0)