Convert ARRAY to OBJECT in javascript - JavaScript Interview Questions

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ม.ค. 2023
  • How to convert Array to Object in JavaScript? Find out here in 1 minute
    🤯 Crash Courses (Single Video)
    Git/Github Crash Course : bit.ly/3JSA5VT
    TypeScript Crash Course : bit.ly/372dZSh
    Angular Crash Course : bit.ly/3DoGJR1
    Vue JS Crash Course : bit.ly/3uDujRl
    Python Crash Course : bit.ly/3Dod7U2
    React Router Crash Course : bit.ly/36YfO2i
    🧑‍🏫 Full Course Playlists
    HTML : bit.ly/36IMq0h
    CSS : bit.ly/3LpRQw6
    JavaScript : bit.ly/3u049tf
    BootStrap : bit.ly/3NA9nDJ
    ES 6 : bit.ly/3DvYCh6
    DOM Playlist : bit.ly/35nMKB7
    ReactJS (Redux & Hooks) : bit.ly/3iMethN
    React with TypeScript : bit.ly/3fQjXtF
    React Hooks: bit.ly/3Vmh7wV
    Redux: bit.ly/3yAIIkl
    NodeJS/ExpressJS : bit.ly/35nN6Yt
    MongoDB / Mongoose : bit.ly/3qPj0EO
    💻 Projects Playlists
    MERN Stack Complete Ecommerce : bit.ly/3ymSs0E
    Web Design HTML+CSS - Home Page : bit.ly/35nZiIB
    Web Design BootStrap - E-Commerce Site : bit.ly/3iPhaz7
    React/Redux/Firebase - Todo-App : bit.ly/3DnekL8
    🕹 Mini Projects (Single Video)
    React - Tic Tac Toe (Redux / Hooks) : bit.ly/3uzLEuy
    React - Game of Flag Quiz (Hooks) : bit.ly/3LpTC0e
    React - Google Translate Clone (Hooks) : bit.ly/3Lo9xvZ
    React - Chat App using Firebase (Hooks) : bit.ly/3wLgymj
    Visit our site: coderdost.com
    🔴 Full Courses List : coderdost.com/courses
    🔴 Full Projects List : coderdost.com/projects
    💾 Source Codes at : github.com/coderdost
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 71

  • @coderdost
    @coderdost  ปีที่แล้ว +4

    Course of JavaScript : bit.ly/3u049tf
    Course of Modern JS. (ES6) : bit.ly/3DvYCh6
    React JS MasterClass (10 Hour) : th-cam.com/video/6l8RWV8D-Yo/w-d-xo.html
    NODE+ EXPRESS+ MONGO MasterClass (12 Hour) : th-cam.com/video/ChVE-JbtYbM/w-d-xo.html
    React Interviews : bit.ly/3QAjAln
    JavaScript Shorts:
    bit.ly/3XhHRQ1
    React Shorts :
    bit.ly/3VfIrMi

  • @veerlamuralikrishna4774
    @veerlamuralikrishna4774 5 หลายเดือนก่อน +8

    simple way
    let obj =[1.2,3]
    console.log({...obj})

  • @Spider-Man_67
    @Spider-Man_67 ปีที่แล้ว +59

    Easy way
    // Convert an array into an object.
    const names = ['Rahul','Krityveer','Anish','Gopal','Parveen'];
    const obj = {...names }
    console.log(obj);

    • @n_fan329
      @n_fan329 ปีที่แล้ว +3

      still not 100% correct, in this case keys are not identical to the values

    • @aliarslanansari
      @aliarslanansari 9 วันที่ผ่านมา

      @@n_fan329 no one want keys identical to values

  • @jayatighosh4626
    @jayatighosh4626 4 หลายเดือนก่อน +5

    let arr = ['Sun', 'Moon', 'Star']
    // Convert array to object
    let obj = {};
    let contertToObj = arr.forEach(i=>obj[i] = i);
    console.log(obj)
    // Convert object to array
    let newArr = [];
    Object.keys(obj).map(key=>newArr.push(key));
    console.log(newArr)

  • @funterban6536
    @funterban6536 2 หลายเดือนก่อน +1

    most of the one channel in youtube which uploaded the best question for interviews in 1 minute

  • @vishal10471
    @vishal10471 11 หลายเดือนก่อน +1

    Please add some more video in this playlist, please

  • @ayushkamar7100
    @ayushkamar7100 ปีที่แล้ว +2

    Ye sir enteries se bi to ho sakta hain ❤❤

  • @rahulkhandelwal1967
    @rahulkhandelwal1967 ปีที่แล้ว

    Nice share 🙌

  • @rahultripathi6935
    @rahultripathi6935 ปีที่แล้ว

    Awesome

  • @faizalkhan2437
    @faizalkhan2437 4 หลายเดือนก่อน

    Object.entries(obj) or if you wanna iterate the value only so you can go with object. Values(obj).

  • @AmritpalSingh-sw3bl
    @AmritpalSingh-sw3bl 8 หลายเดือนก่อน

    Using for each loop we can handle it easily

  • @adarshkhatri993
    @adarshkhatri993 ปีที่แล้ว +8

    Object.keys(), Object.values(), Object.entries() to convert into array??

  • @vaibhav_gamingg
    @vaibhav_gamingg ปีที่แล้ว +1

    Bhaii ap kese kr rhe ho sb
    Muje JS smj he nhi atti thi and u make it very simple for me thanku.

  • @killerdroid99
    @killerdroid99 9 หลายเดือนก่อน

    you can use a record for these conversions

  • @syedjaidahmed1728
    @syedjaidahmed1728 11 หลายเดือนก่อน

    big fan

  • @syedjaidahmed1728
    @syedjaidahmed1728 11 หลายเดือนก่อน

    Love from Bangladesh

  • @ZigZag-ry3zm
    @ZigZag-ry3zm ปีที่แล้ว +2

    Which extension do you use to get that return info while changing something in the function?

  • @abhishekstorycreator
    @abhishekstorycreator ปีที่แล้ว

    Object.values()

  • @akshaysalunkhe3226
    @akshaysalunkhe3226 ปีที่แล้ว

    Object.assign({}, object name)

  • @vaxff1945
    @vaxff1945 9 หลายเดือนก่อน

    logic was simple but code should be readabe i was scared after this short later i understood

  • @iron_man____
    @iron_man____ 8 หลายเดือนก่อน

    let arr = ['a','b','c']
    let obj = arr.reduce((a,it,i)=>{
    a[it] = it
    return a
    },{})
    console.log(obj)
    //{ a: 'a', b: 'b', c: 'c' }

  • @n_fan329
    @n_fan329 ปีที่แล้ว

    let tab=[]
    for (let val in obj){
    tab.push(obj[val])
    }
    console.log(tab2)

  • @zaynff2m860
    @zaynff2m860 5 หลายเดือนก่อน

    Sir theem kon si hi

  • @hirenahir76200
    @hirenahir76200 2 หลายเดือนก่อน

    Bro ye answers side me kese aa rahe ge?

  • @anshulsingh6825
    @anshulsingh6825 ปีที่แล้ว

    Object. Keys(array_name)

  • @davidbaraiya2649
    @davidbaraiya2649 ปีที่แล้ว +1

    Which extention for inline result ?

  • @prabhattambe4047
    @prabhattambe4047 ปีที่แล้ว

    Array.from()

  • @diveshpatidar5159
    @diveshpatidar5159 7 หลายเดือนก่อน

    Let newArr = [...Object.values(obj)];
    //['a', 'b', 'c']

  • @Yaduvanshi-nw3yr
    @Yaduvanshi-nw3yr 4 หลายเดือนก่อน

    Solution -------->
    Object.keys(Obj).map(i =>obj[i])

  • @nakulnagariya7736
    @nakulnagariya7736 ปีที่แล้ว

    Object.entriesFrom

  • @improve4477
    @improve4477 ปีที่แล้ว

    awesome,
    Software ka name batao na!

    • @coderdost
      @coderdost  ปีที่แล้ว

      quokka js extension

  • @channel6k
    @channel6k ปีที่แล้ว

    let arr=["a","b","c"];
    let obj={};
    for( let i=0 ;i

    • @coderdost
      @coderdost  ปีที่แล้ว

      Yes that will also work

  • @vishal10471
    @vishal10471 ปีที่แล้ว

    Arr.reverse

  • @pankajsharma-rf1ov
    @pankajsharma-rf1ov ปีที่แล้ว

    My question is why it is taking only the last one in case of string means
    ({...a,it:it}) o/p {it:"a"}
    But why ({...a,[it]:it}) gives right answer
    I am still not clarified.

    • @coderdost
      @coderdost  ปีที่แล้ว +2

      When you put a square bracket on key of an object. The variable is evaluated and then the result is assigned as key string. This feature is used a lot in forms.
      {[e.target.name]:e.target.value} this kind of syntax you will see in lot of frontend forms..

    • @pankajsharma-rf1ov
      @pankajsharma-rf1ov ปีที่แล้ว

      @coderdost after over a time I realised that when the data is entered in the object like {it:"a"} and in further iteration data is entered with different value but with the same key that's why our last key value is modified or replaced with new one bcz key is the same.

    • @coderdost
      @coderdost  ปีที่แล้ว

      👍🏻 yes

  • @user-tg1wd2xb6j
    @user-tg1wd2xb6j 10 หลายเดือนก่อน

    Aap kaun sa code editor use karte ho. yeah console ki command bhi code mein hi Dikhai ja raha hai ya aap kaise kar rahe ho.
    Aap ko subscribe Kar Diya Hai Ab lajmi batana.

    • @coderdost
      @coderdost  10 หลายเดือนก่อน

      VScode with Quokka JS extension

  • @jamshedahmad6069
    @jamshedahmad6069 ปีที่แล้ว +4

    Using the Object.assign() method to convert an array to an object ,e.g. const obj = Object.assign({}, arr).
    Using the spread syntax (...) to convert an array to an object, e.g. const obj = {...arr}.
    Using the Array.forEach() method to iterate over all items and add them as a key-value pair to an object.
    Using the Object.fromEntries() method to convert an array of key-value pairs to an object, e.g. const obj = Object.fromEntries(arr).

  • @murtazashahidofficial3790
    @murtazashahidofficial3790 11 หลายเดือนก่อน

    Which code editor is this? Kindly share

    • @coderdost
      @coderdost  11 หลายเดือนก่อน

      VScode but with custom theme (setting json modified)

    • @murtazashahidofficial3790
      @murtazashahidofficial3790 11 หลายเดือนก่อน

      @@coderdost sir please ye kese karty hen aap bata sakty hen please mai buhat try karha hun mere vs code mai JS nhi run hora mai dhundh dhundh ke thak gya hun

  • @scriptDoodle
    @scriptDoodle 10 หลายเดือนก่อน

    Which extension gives results beside code like yours?

    • @coderdost
      @coderdost  10 หลายเดือนก่อน

      Quokka JS

  • @tigerguru2850
    @tigerguru2850 10 หลายเดือนก่อน

    Ye konsa theme hai??

    • @coderdost
      @coderdost  10 หลายเดือนก่อน

      Dark theme + Customized settings.json of VSCode

    • @tigerguru2850
      @tigerguru2850 10 หลายเดือนก่อน

      @@coderdost ispe ek shorts bnao.

  • @real_vincenzo
    @real_vincenzo ปีที่แล้ว

    Kitne time Lage aapko javascript Sikhne mein ? Aapki tarah kaise sikhu ?

    • @coderdost
      @coderdost  ปีที่แล้ว

      I am using from 2010

  • @ajaypanchal1106
    @ajaypanchal1106 10 หลายเดือนก่อน +1

    const arr = [1, 23, 4, 56, 7];
    // convert it into object
    const out = arr.reduce((num, crt, i, ar) => {
    return { ...num, [crt]: crt };
    }, {});
    console.log(out);
    const rev = Object.values(out).reduce((prev, current, index, arr) => {
    return [...prev, current];
    }, []);
    console.log(rev);

  • @sashirkl
    @sashirkl ปีที่แล้ว +1

    Boss kuch samajh mein nahin aya . And funny part is i know programming. Mujhe kuch knowledge hoke agar samajh nahin aya dusre ko kya aega

    • @coderdost
      @coderdost  ปีที่แล้ว

      these are just tricky question ppl ask sometime in interviews. They are not normal in everyday work of JS developer. But good for practice.

    • @hishamkhan4913
      @hishamkhan4913 ปีที่แล้ว

      Bro .. coding se upar he javascript... Js padho sahi se... He explained perfectly...

  • @unknowneditor2799
    @unknowneditor2799 ปีที่แล้ว

    My question is that can program understand who is subject and object in array sentence ?

    • @coderdost
      @coderdost  ปีที่แล้ว

      program must use some library to understand that language, other wise by simple logic its not possible.

  • @akash.web_dev
    @akash.web_dev 10 หลายเดือนก่อน +1

    const arr=['a','b','c']
    let obj = Object.assign({},arr)
    console.log(obj);
    let array= Object.entries(obj)
    console.log(array.flat());
    array to object and object to array
    ye ek good approch hai ya nahi

  • @naveensanai5378
    @naveensanai5378 ปีที่แล้ว

    video ko reverse karo ho jayega 😂😂

  • @webmobi2773
    @webmobi2773 11 หลายเดือนก่อน

    var emptyObj= { }
    are.forEach((val)=> {
    emptyObj[val] = val;
    }
    console.log(emptyObj);
    🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉

  • @pritamkeshri8389
    @pritamkeshri8389 ปีที่แล้ว

    Awesome