let x = {a:1,b:2};
const xarr = [];
for(let i in x){
    xarr.push(i); 
    console.log(i);
}
//output is a, b but I want output 1 and 2.
Thanks in advance
let x = {a:1,b:2};
const xarr = [];
for(let i in x){
    xarr.push(i); 
    console.log(i);
}
//output is a, b but I want output 1 and 2.
Thanks in advance
 
    
     
    
    Simply use Object.values(obj) .Is Return with array format
let x = {a:1,b:2};
var res =Object.values(x);
console.log(res.toString()) 
    
    In your code you need to use x[i] not i for printing
   let x = {a:1,b:2};
    const xarr = [];
    for(let i in x){
             console.log(x[i]);
     xarr.push(x[i]); 
    }
    
         console.log(xarr); 
    
    A for loop in javascript will iterate over the keys of an object, if you want the values you will have to fetch then om the object using that key.
let x = {a:1,b:2};
const xarr = [];
for(let i in x){
 xarr.push(x[i]); 
 console.log(x[i]);
}