Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

substr() javascript

const str = 'substr';

console.log(str.substr(1, 2)); // (1, 2): ub
console.log(str.substr(1)); // (1): ubstr

/* Percorrendo de trás para frente */
console.log(str.substr(-3, 2)); // (-3, 2): st
console.log(str.substr(-3)); // (-3): str
Comment

js substr

//str.substr(start[, length])
var str = 'abcdefghij';

console.log('(1, 2): '   + str.substr(1, 2));   // '(1, 2): bc'
console.log('(-3, 2): '  + str.substr(-3, 2));  // '(-3, 2): hi'
console.log('(-3): '     + str.substr(-3));     // '(-3): hij'
console.log('(1): '      + str.substr(1));      // '(1): bcdefghij'
console.log('(-20, 2): ' + str.substr(-20, 2)); // '(-20, 2): ab'
console.log('(20, 2): '  + str.substr(20, 2));  // '(20, 2): '
Comment

Substring in Javascript using substr

const str = "Learning to code";
// start index is 1, length is 4
console.log(str.substr(1, 10));
// start index is 3, length is 2
console.log(str.substr(3, 2));

// length not given
// string extract to end of the string
console.log(str.substr(5));
Comment

substr JavaScript

//substr() is similar to slice().
//The difference is that the second parameter specifies the length of the extracted part

let str = "Apple, Banana, Kiwi";
let part = str.substr(7, 6);

// >> Banana

//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
Comment

JavaScript substr()

var string = "WelcomeToSofthunt.netTutorialWebsite";
one = string.substr(0, 7)
two = string.substr(7, 2)
three = string.substr(9,12)
four = string.substr(21, 8)
five = string.substr(29,36)
six = string.substr(0)
 
document.write(one);
document.write(two);
document.write(three);
document.write(four);
document.write(five);
document.write(six);
Comment

JavaScript substr() Syntax

string.substr(startIndex[, length])
Comment

PREVIOUS NEXT
Code Example
Javascript :: ternary operator jquery 
Javascript :: extract from a string in javascript 
Javascript :: or operator javascript 
Javascript :: javascript get content of input 
Javascript :: javascript foreach arrow function 
Javascript :: ngmodel component angular 
Javascript :: js nuxt read/set cookie 
Javascript :: difference between package.json and package lock.json 
Javascript :: factorial js 
Javascript :: for:each in lwc js 
Javascript :: convert exp date token to date 
Javascript :: check if an array contains a number in javascript 
Javascript :: angular disable select dropdown 
Javascript :: how to add all values of array together js 
Javascript :: moment format heure 
Javascript :: make an object javascript 
Javascript :: Self Invoking Function Simpler Syntax 
Javascript :: moment clone 
Javascript :: DC League of Super-Pets 
Javascript :: react 18 rendering twice 
Javascript :: jest tranform image 
Javascript :: get before 6 month date javascript node js 
Javascript :: javascript array clear 
Javascript :: javascript spread operator 
Javascript :: // Write a function that takes a number (a) as argument // Split a into its individual digits and return them in an array // Tipp: you might want to change the type of the number for the splitting 
Javascript :: create express js project 
Javascript :: javascript multidimensional array 
Javascript :: added font to react native 
Javascript :: entypo icons react native 
Javascript :: discord.js make channel private 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =