Find and Replace String Methods

Video

JavaScript Notes

JavaScript
    // findall.js
    // searching through a string to find all matches
    // and do a find and replace
    // with indexOf( ) and replace( )
    // without using Regular Expressions
    
    let log = console.log;
    let paragraph = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vitae suscipit optio ab et soluta illo numquam at, eos qui similique voluptates sapiene quis quisquam libero, dicta neque consequuuntur. Asperiores, temporibus.'
    
    let find = 'x';
    let replace = '';
    let newPara = "".concat(paragraph);	                // creates a copy of the paragraph object 
    if(paragraph.indexOf(find) > -1){
        paragraph = paragraph.replace(find, replace)	// replaces what is in ‘find’ with ‘replace’
                                                        // and updates the existing string
        log(paragraph);
    }