JSFiddle - React, Tailwind, and code Playground

by Mobeen Sarwar

JavaScript

var obj = {

    0:{id: 1, name: 'one'},
    1:{id: 2, name: 'two'},
    2:{id: 3, name: 'three'},
    3:{id: 4, name: 'four'}
};
var keys = Object.keys(obj);
var values = Object.values(obj);
var newObj = {};

 function array_move(arr, old_index, new_index) {
    if (new_index >= arr.length) {
        var k = new_index - arr.length + 1;
        while (k--) {
            arr.push(undefined);
        }
    }
    arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);             
  }  
  
 values = array_move(values,1,4);

/*  keys.forEach(function(el, i){
   newObj[el] = values[i]; 
 });  */
/* console.log(keys); */
console.log(values);