Skip to content

Instantly share code, notes, and snippets.

@jayprajapati857
Last active February 28, 2019 13:49
Show Gist options
  • Save jayprajapati857/b7ed7181c57cfd2ffacc6d03a0070e72 to your computer and use it in GitHub Desktop.
Save jayprajapati857/b7ed7181c57cfd2ffacc6d03a0070e72 to your computer and use it in GitHub Desktop.
Add an object at first place in an array
var list = data; // here data is itself an array
list.splice(0, 0,
{
definition_id: "-1", // key value pair
display_name: ""
}
);
function replaceAt(string, index, replace) {
return string.substring(0, index) + replace + string.substring(index + 1);
}
function sayHello() {
document.write("Hello, Coding Ground!");
var time_1 = performance.now();
var arr = [23, 45, 12, 67];
arr = [34, ...arr]; // RESULT : [34,23, 45, 12, 67]
document.write(arr);
var time_2 = performance.now();
document.write("HELLO");
document.write("\n\n"+(time_2-time_1)+"\n\n\n");
var case1 = (time_2-time_1);
document.write("HELLO");
var time_3 = performance.now();
var arr = [23, 45, 12, 67];
arr.unshift(34);
document.write(arr);
var time_4 = performance.now();
document.write("HELLO");
document.write("\n\n"+(time_4-time_3)+"\n\n\n");
var case2 = (time_4-time_3);
document.write("HELLO");
var time_5 = performance.now();
var arr = [23, 45, 12, 67];
arr.splice(0, 0,
{
definition_id: "-1", // key value pair
display_name: ""
}
);
document.write(arr);
var time_6 = performance.now();
document.write("HELLO");
document.write("\n\n"+(time_6-time_5)+"\n\n\n");
var case3 = (time_6-time_5);
document.write("HELLO");
document.write ("<br>");
var mul = 1;
document.write (case1*mul);
document.write ("<br>");
document.write (case2*mul);
document.write ("<br>");
document.write (case3*mul);
}
sayHello();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment