DEV Community

Cover image for Object and object properties.!
Hodiev
Hodiev

Posted on • Edited on

Object and object properties.!

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 konstruktorusuli.!

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'}
Enter fullscreen mode Exit fullscreen mode

obekt litiralusuli.!

const car={
    type:"BMW",
    price:"50000$",
    wight:"1500kg",
    speed:"300km/h"
};
console.log(car);
// natija - {type: 'BMW', price: '50000$', wight: '1500kg', speed: '300km/h'}
Enter fullscreen mode Exit fullscreen mode

Obektlarning xususiyatlari.!!!

  1. 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$
Enter fullscreen mode Exit fullscreen mode

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}
Enter fullscreen mode Exit fullscreen mode

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'}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)