Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

slice string js

const str = 'The quick brown fox jumps over the lazy dog.';

console.log(str.slice(31)); // expected output: "the lazy dog."

console.log(str.slice(4, 19)); // expected output: "quick brown fox"

console.log(str.slice(-4)); // expected output: "dog."

console.log(str.slice(-9, -5)); // expected output: "lazy"

// source : https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/String/slice
Comment

The slice JavaScript string method

// You use this method to cut out a substring from an entire string.
// We will use this method to cut out the remaining part of a word (excluding the first letter):

const word = "freecodecamp"

const remainingLetters = word.substring(1)
// reecodecamp
Comment

string splice

newStr = str.split(''); // or newStr = [...str];
newStr.splice(2,5);
newStr = newStr.join('');
Comment

slice string javascript

let str = "Learning to code";

// slice from index 2 to end
let str1 = str.slice(2);
console.log(str1);

// slice from index 1 to index 8
let str2 = str.slice(1, 8);
console.log(str2);

// slice from index 5 to index (str.length - 3)
let str3 = str.slice(5, -3);
console.log(str3);

// slice from index 100 to end (returns '')
let str4 = str.slice(100);
console.log(str4);

// slice from index 0 to end of string
let str5 = str.slice(0);
console.log(str5);
Comment

can i use splice in string of javascript

yes i can
Comment

javascript string slice

let x = ["a", "b", "c", "d", "e", "f"];

console.log(Array.prototype.slice.call("abcdefg"))
/*[ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ]*/
/*slice can turn a string into an array with its letters as elements*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: copy element jquery 
Javascript :: javascript remove uniques from array 
Javascript :: js date get hours 
Javascript :: google gapi auth2 get current token 
Javascript :: remove all sign that is not a-b in string js 
Javascript :: regular expression in elastic 
Javascript :: how to change background color using js 
Javascript :: checkbox event listeners 
Javascript :: react list 
Javascript :: math.max js 
Javascript :: form validation jquery input array 
Javascript :: js .touppercase 
Javascript :: toastr options 
Javascript :: javascript sleep 1 second" 
Javascript :: electron get printer list 
Javascript :: get all matches regex javascript 
Javascript :: xlsx to json using xlsx react 
Javascript :: .text javascript 
Javascript :: angular implementing Validator 
Javascript :: sublime javascript autocomplete 
Javascript :: printing in a single line in javascript 
Javascript :: $.post javascript 
Javascript :: creating react app 
Javascript :: bootstrap searchable pagination table example jquery 
Javascript :: how to replace all occurrences of a string in javascript 
Javascript :: Get element by ID with only a partial string 
Javascript :: jquery api 
Javascript :: send post request 
Javascript :: get json data into array of object 
Javascript :: js add class to html 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =