Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

time complexity of slice javascript

Array.prototype.slice is O(n), where n is the number of elements in the slice.

String.prototype.slice is O(1) time complexity

//example

let nested = {name: "test"};
var a = [nested];
console.log(a)
var b = a.slice(0, 1);
console.log(b)
a[0].name = "abc";
console.log(a === b);          // false, `b` is a copy
console.log(a[0] === b[0]);    // true, `nested` was not copied
console.log(b[0] === nested);  // true
console.log(b[0].name);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to set variable in discord.js 
Javascript :: mongoose max record 
Javascript :: express formidable 
Javascript :: isnan 
Javascript :: array within array javascript 
Javascript :: what does connect do in redux 
Javascript :: nodemon exclude 
Javascript :: javascript grpc timestamp 
Javascript :: js queryselector 
Javascript :: what is next.js 
Javascript :: shopify template routing map 
Javascript :: npm i images=pdf 
Javascript :: key codes javascript 
Javascript :: The toString() Method 
Javascript :: display component in popup angular 8 
Javascript :: escape character javascript 
Javascript :: max value in an array 
Javascript :: node red json array 
Javascript :: firebase get subcollection 
Javascript :: check if jwt token is valid 
Javascript :: jq not contains 
Javascript :: how to build and deploy a react app to github pages 
Javascript :: jquery scroll to bottom of div 
Javascript :: js standard global 
Javascript :: enable javascript chrome 
Javascript :: search for diff in two JSON 
Javascript :: array index javascript 
Javascript :: sample promise.all javascript 
Javascript :: json date format 
Javascript :: hoisting in javascript mdn 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =