Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 1.04 KB

File metadata and controls

26 lines (19 loc) · 1.04 KB

substr and substring

  • Use: Syntax: substr MDN takes parameters as (from, ?length). Syntac: substring MDN takes parameters as (start, ?end(exclusive)).
 // get value using substr
 console.log(str.substr(1, 10)); // 'ommonSourc'
 
 // get value using substring
 console.log(str.substring(1, 10)); // 'ommonSour'
 // if we start from 0 both behave the same.
 console.log(str.substr(0, 10)); // 'commonSour'
 console.log(str.substring(0, 10)); // 'commonSour'

 // Example: Remove first and last character from a given string ❓

 console.log(str.substr(1, str.length - 2)) // ommonSourceOfTrut

 // Substring takes indices
 console.log(str.substring(1, str.length - 1)) // ommonSourceOfTrut

Substr Browser compatibility

Substr Browser compatibility