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

sub function javascript

// Simple Substraction Function in Javascript
function sub(a, b) {
return a-b
}
console.log(sub(6, 2))
Comment

PREVIOUS NEXT
Code Example
Javascript :: why does array index start from 0 
Javascript :: how to check empty string array in javascript 
Javascript :: javascript exeit from loop 
Javascript :: keyboard close when typing react native 
Javascript :: how to use break in javascript 
Javascript :: simulate mouse click javascript 
Javascript :: js octal 
Javascript :: api integration for web pages in next js 
Javascript :: express get port from request 
Javascript :: create file node 
Javascript :: object properties 
Javascript :: for in in javascript 
Javascript :: upload file in node 
Javascript :: javaScript Math.log() Method 
Javascript :: break loop after time javascript 
Javascript :: react-validex 
Javascript :: react native stopwatch 
Javascript :: css striped background 
Javascript :: how can we access the data from array object in javascript 
Javascript :: types of method in js 
Javascript :: swap first and last element in array javascript 
Javascript :: convert json to arraylist java 
Javascript :: Is Even 
Javascript :: Function.prototype.apply.call(console[level], console, argsWithFormat); 
Javascript :: json 
Python :: tkinter how to make a root non rezizable 
Python :: sqlalchemy python install 
Python :: error tokenizing data. c error 
Python :: change figure size pandas 
Python :: selenium python maximize window 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =