Upgrade Skill Di ITBOX Jadi Lebih Hemat
Special Diskon 50%
Sampai 16 November 2026!
Hari
Jam
Menit
Detik
GARUDABOX

Larik objek

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #50249
    Tufel Shobrun
    Participant

      Halo kak

      Untuk yg larik object itu agar kluar hasil ny
      Sperti yang brada di materi itu gmna cara console.log nya ya ?

      #50570
      Coach Vincent
      Moderator

        contoh:
        var items = [
        {
        id: 1,
        name: ‘abc’
        }
        ]

        console.log(items)

        console.log sesuai nama var nya

        #130884

        var items =[
        {
        name : “Asus”,
        type : “Laptop”,
        price : 75000000
        },
        {
        name : “Dell”,
        type : “Laptop”,
        price : 70000000
        },
        {
        name : “Corsair”,
        type : “Ram”,
        price : 12500000
        }
        ];

        function ubahKeArrayObjek(array2D){
        var hasil = [];
        var tempObj = {};

        for(var i=0; i<array2D.length; i++){
        tempObj.name = array2D[i][0];
        tempObj.type = array2D[i][1];
        tempObj.price = array2D[i][2];

        hasil.push(tempObj);
        tempObj = {};
        }
        return hasil;
        }

        PERTANYAAN :
        GIMANA CARA MENJALAN KAN UNTUK FUNCTION OBJEK SEPERTI INI?

        #170269
        Coach Vincent
        Moderator

          invoke function atau call function sesuai namanya kak.

          ubahKeArrayObjek(items);

          terima kasih

          #192101
          Aldy
          Participant

            var items = [
            [“Asus”, “laptop”, 7500000],
            [“Dell”, “laptop”, 7000000],
            [“Corsair”, “ram”, 1250000],
            ]

            function changearrayobject(array2d){
            var result = [];
            var tempObj = {};

            for(var i = 0; i < array2d.length; i++){
            tempObj.name = array2d[i] [0];
            tempObj.type = array2d[i] [1];
            tempObj.price = array2d[i] [2];

            result.push(tempObj);
            tempObj = {};
            }
            return result;
            }
            changearrayobject(items);

            tolong ini kenapa gak running ya?

            #194865
            Coach Vincent
            Moderator

              Harus menggunakan console.log nya kak

            Viewing 6 posts - 1 through 6 (of 6 total)
            • You must be logged in to reply to this topic.
            Shopping cart0
            There are no products in the cart!
            Continue shopping