Javascript

Home Load Console Selectors CSS Form Strings If Else Array Reg Exp Date & Time setTimeout JSON Loops Objects Animation Fat Arrow Class Import IIFE undefined Tabulator.js ES6 Event Listeners AJAX Hide Elements Create Elements Checkbox ejs
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

Javascript : Strings

2022-07-18

String Basics

var demo = "Rob is amazing.";

// get position of string/character
var pos = demo.indexOf("amazing"); // 7

// cut out portion of string
var sub = demo.substring(1, 6); // "ob is"

// replace a portion of the string
var rep = demo.replace("amazing", "really good looking");   

// slice off the last characters of a string
var sli = demo.slice(0, -2);  // Rob is amazin

// slice off the last comma
orderStr.replace(/^,/, '');

// get everything to the right of a position
var sli2 = demo.slice(4); // is amazing.

Other Methods

match();  // used with Reg Exp
search(); // used with Reg Exp
split();   // used with arrays