Takip Edin

JAVASCRIPT

Javascript’te Object Literals İle Alakalı Uygulamalar

Javascript'te Object Literals İle Alakalı Uygulamalar - Öne Çıkan Görsel
// Object Literals

let val;

let personel = {
    ad: 'Cihan',
    soyad: 'Akarpınar',
    yas: 27,
    hobiler: ['futbol oynamak', 'film izlemek', 'yüzmek'],
    adres: {
        il: 'Denizli',
        ilce: 'Pamukkale',
        ulke: 'Türkiye'
    },

    dogumYili: function () {
        return 2020 - this.yas; // this, personel nesnesini temsil eder.
    }
};

val = personel.ad;
val = personel.soyad;
val = personel['ad'];
val = personel.yas;
val = personel.hobiler;
val = personel.hobiler[2];
val = personel.hobiler.length;
val = personel.adres;
val = personel.adres.il;
val = personel.adres['ilce'];
val = personel.dogumYili();

// console.log(val);
// console.log(typeof personel);

let calisan = [
    {ad : 'Cihan', soyad : 'Akarpınar'},
    {ad : 'Ayşen', soyad : 'Aksoy'},
    {ad : 'Kadir', soyad : 'Özdinçer'}
];

val = calisan[0];
val = calisan[1].ad;

// console.log(val);

for (let i = 0; i < calisan.length; i++) {
    console.log(calisan[i].soyad);
}

Aşağıda verilen örnek object literal yapısını kullanarak araçlar için servis kayıt bilgisi giriniz.

Araç Bilgileri:

id : volvoxc60_t8

model : xc60

year : 2017

color : silver

service records :

=>     id : volvoxc60_t8_1

=>     date :  28.01.2018

=>     km : 12000

=>     overall charge : 1200

=>     service details :

  • id : 1, operation : filter change, price : 400
  • id : 2, operation : brake fluid, price : 400
  • id : 3, operation : oil change, price : 400

=>     id : volvoxc60_t8_2

=>     date :  17.01.2019

=>     km : 23000

=>     overall charge : 2000

=>     service details :

  • id : 1, operation : filter change, price : 450
  • id : 2, operation : brake fluid, price : 450
  • id : 3, operation : oil change, price : 400
  • id : 4, operation : balata change, price : 700
var cardatas = [

    {
        id: 'volvoxc60_t8',
        model: 'volvo xc60',
        year: 2017,
        color: 'silver',
        service_records: [
            {
                id: 'volvoxc60_t8_1',
                date: '28.01.2018',
                km: '12000',
                charge: 1200,
                detail: [
                    { id: 'volvoxc60_t8_1_1', statement: 'filter change price', charge: 300 },
    
                    { id: 'volvoxc60_t8_1_2', statement: 'brake fluid price', charge: 300 },
    
                    { id: 'volvoxc60_t8_1_3', statement: 'oil change price', charge: 300 }
                ]
            },
    
            {
                id: 'volvoxc60_t8_2',
                date: '17.01.2019',
                km: '23000',
                charge: 2000,
                detail: [
                    { id: 'volvoxc60_t8_2_1', statement: 'filter change price', charge: 450 },
    
                    { id: 'volvoxc60_t8_2_2', statement: 'brake fluid price', charge: 450 },
    
                    { id: 'volvoxc60_t8_2_3', statement: 'oil change price', charge: 400 },
    
                    { id: 'volvoxc60_t8_2_4', statement: 'balata change price', charge: 700 }
                ]
            }
        ]
    },

    {
        id: 'mazdacx_5',
        model: 'mazda cx5',
        year: 2017,
        color: 'red',
        service_records: [
            {
                id: 'mazdacx_5_1',
                date: '28.01.2018',
                km: '12000',
                charge: 1200,
                detail: [
                    { id: 'mazdacx_5_1_1', statement: 'filter change price', charge: 300 },
    
                    { id: 'mazdacx_5_1_2', statement: 'brake fluid price', charge: 300 },
    
                    { id: 'mazdacx_5_1_3', statement: 'oil change price', charge: 300 }
                ]
            },
    
            {
                id: 'mazdacx_5_2',
                date: '17.01.2019',
                km: '23000',
                charge: 2000,
                detail: [
                    { id: 'mazdacx_5_2_1', statement: 'filter change price', charge: 450 },
    
                    { id: 'mazdacx_5_2_2', statement: 'brake fluid price', charge: 450 },
    
                    { id: 'mazdacx_5_2_3', statement: 'oil change price', charge: 400 },
    
                    { id: 'mazdacx_5_2_4', statement: 'balata change price', charge: 700 }
                ]
            }
        ]
    },

    {
        id: 'toyotarav_4',
        model: 'toyota rav4',
        year: 2017,
        color: 'white',
        service_records: [
            {
                id: 'toyotarav_4_1',
                date: '28.01.2018',
                km: '12000',
                charge: 1200,
                detail: [
                    { id: 'toyotarav_4_1_1', statement: 'filter change price', charge: 300 },
    
                    { id: 'toyotarav_4_1_2', statement: 'brake fluid price', charge: 300 },
    
                    { id: 'toyotarav_4_1_3', statement: 'oil change price', charge: 300 }
                ]
            },
    
            {
                id: 'toyotarav_4_2',
                date: '17.01.2019',
                km: '23000',
                charge: 2000,
                detail: [
                    { id: 'toyotarav_4_2_1', statement: 'filter change price', charge: 450 },
    
                    { id: 'toyotarav_4_2_2', statement: 'brake fluid price', charge: 450 },
    
                    { id: 'toyotarav_4_2_3', statement: 'oil change price', charge: 400 },
    
                    { id: 'toyotarav_4_2_4', statement: 'balata change price', charge: 700 }
                ]
            }
        ]
    },

]

console.log(cardatas[0]);
console.log(cardatas[0].id);
console.log(cardatas[0].model);
console.log(cardatas[0].year);
console.log(cardatas[0].color);
console.log(cardatas[0].service_records);
console.log(cardatas[0].service_records[1]);
console.log(cardatas[0].service_records[1].date);
console.log(cardatas[0].service_records[1].km);
console.log(cardatas[0].service_records[1].charge);
console.log(cardatas[0].service_records[1].detail[2]);
console.log(cardatas[0].service_records[1].detail[2].statement);
Devamını oku

Popüler

error: Content is protected !!