Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

find every character string match JavaScript

const sourceStr = 'I learned to play the Ukulele in Lebanon.';
const searchStr = 'le';
const indexes = [...sourceStr.matchAll(new RegExp(searchStr, 'gi'))].map(a => a.index);
console.log(indexes); // [2, 25, 27, 33]
Comment

find every character string match JavaScript

function locations(substring,string){
  var a=[],i=-1;
  while((i=string.indexOf(substring,i+1)) >= 0) a.push(i);
  return a;
}

console.log(locations("s","scissors"));
//-> [0, 3, 4, 7]
Comment

find every character string match JavaScript

function indexesOf(string, regex) {
    var match,
        indexes = {};

    regex = new RegExp(regex);

    while (match = regex.exec(string)) {
        if (!indexes[match[0]]) indexes[match[0]] = [];
        indexes[match[0]].push(match.index);
    }

    return indexes;
}
Comment

find every character string match JavaScript

function charPos(str, char) {
  return str
         .split("")
         .map(function (c, i) { if (c == char) return i; })
         .filter(function (v) { return v >= 0; });
}

charPos("scissors", "s");  // [0, 3, 4, 7]
Comment

find every character string match JavaScript

indices = (c, s) => s
          .split('')
          .reduce((a, e, i) => e === c ? a.concat(i) : a, []);

indices('?', 'a?g??'); // [1, 3, 4]
Comment

find every character string match JavaScript

const findIndices = (str, char) => str.split('').reduce( (indices, letter, index) => { letter === char && indices.push(index); return indices }, [] );
Comment

find every character string match JavaScript

let indices = [];
let array = "scissors".split('');
let element = 's';
    
let idx = array.indexOf(element);
    
while (idx !== -1) {
   indices.push(idx+1);
   idx = array.indexOf(element, idx + 1);
}
console.log(indices);
Comment

PREVIOUS NEXT
Code Example
Javascript :: Javascript highest to lowest 
Javascript :: Producing a Promise 
Javascript :: mapa gratis leaflet 
Javascript :: html css and javascript for web developers 
Javascript :: You may need an appropriate loader to handle this file type when importing images 
Javascript :: set body angle matter.js 
Javascript :: setting a date range using yup on react date picker 
Javascript :: mongoose populate not working 
Javascript :: bug in javascript 
Javascript :: Using anonymous functions as arguments of other functions 
Javascript :: when reload the page the route gone in react js laravel 
Javascript :: input creates console log delay 
Javascript :: fonction fleche js 
Javascript :: image uploading payload 
Javascript :: buffer to base 64 online 
Javascript :: foramt file with jq 
Javascript :: $("#right-button").click(function() { event.preventDefault(); $(".table-responsive").animate( { scrollLeft: "+=300px" }, "slow" ); }); 
Javascript :: cant resolve module after typescript install 
Javascript :: tour-app-api 
Javascript :: Temporarily Edit Text on Any Website 
Javascript :: missing state 
Javascript :: poo javascript heritage 
Javascript :: jquery hide elevateZoom 
Javascript :: forward slash in ajax url 
Javascript :: Edit todo list react-redux 
Javascript :: Bitwise IndexOf Shorthand in javascript 
Javascript :: angular assign class invalid form 
Javascript :: express static page 
Javascript :: react native asyncstorage getitem 
Javascript :: appolo query data in angular graphql 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =