SaaS News Hubb
Advertisement
  • Home
  • News
  • Software Engineering
  • Software Development
  • SAAS Applications
  • Contact Us
No Result
View All Result
  • Home
  • News
  • Software Engineering
  • Software Development
  • SAAS Applications
  • Contact Us
No Result
View All Result
SaaS News Hubb
Home Software Development

JavaScript String replaceAll

by admin
April 9, 2022
in Software Development
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter

Replacing a substring of text within a larger string has always been misleading in JavaScript. I wrote Replace All Occurrences of a String in JavaScript years ago and it’s still one of my most read articles.

The confusion lies in that replace only replaces the first occurrence of a substring, not all occurrences. For example:

'yayayayayaya'.replace('ya', 'na');
// nayayayayaya

To replace all instances of a substring, you’ve needed to use a regular expression:

'yayayayayaya'.replace(/ya/g, 'na');
// nananananana

Using regular expressions is certainly powerful but let’s be honest — oftentimes we simply want to replace all instances of a simple substring that shouldn’t require a regular expression.

Luckily, this year the JavaScript language provided us with String.prototype.replaceAll, a method for replacing without using regular expressions:

'yayayayayaya'.replaceAll('ya', 'na');
// nananananana

Sometimes an API exists in a confusing format and standards bodies simply need to improve the situation. I’m glad they did so with replaceAll!

Website performance monitoring
Website performance monitoring
Website performance monitoring
Website performance monitoring
  • Conquering Impostor Syndrome

    Conquering Impostor Syndrome

    Two years ago I documented my struggles with Imposter Syndrome and the response was immense.  I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions.  I’ve even caught myself reading the post…

  • Interview with a Pornhub Web Developer
  • Link Nudging Using Dojo
  • Geolocation API

    Geolocation API

    One interesting aspect of web development is geolocation; where is your user viewing your website from? You can base your language locale on that data or show certain products in your store based on the user’s location. Let’s examine how you can…



Source link
Previous Post

Protocol and Pluralsight: Key Takeaways in Recruiting and Retaining Talent

Next Post

Paxos

Related Posts

Software Development

Report | Evaluating DevSecOps Tools

May 19, 2022
Software Development

Avoiding Design by Committee

May 19, 2022
Software Development

Global skills and literacy shortfalls in data and analytics

May 18, 2022
Software Development

Why Full Stack Web Development Is Still a Viable Path

May 18, 2022
Software Development

Reskill Non-Tech Talent for Software Careers

May 17, 2022
Software Development

20 Fantastic Lightroom Presets for Adding Instagram Effects to Your Shots

May 17, 2022

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Popular

News

Customer Acquisition Strategy for SaaS Companies: A Complete Guide

May 19, 2022
Software Engineering

Crystal balls and clairvoyance: Future proofing in a world of inevitable change

May 19, 2022
Software Engineering

Tell a Compelling Story: Pitch Deck Components That Persuade

May 19, 2022
Software Engineering

Skyflow Privacy and Compliance with Sean Falconer

May 19, 2022
Software Development

Report | Evaluating DevSecOps Tools

May 19, 2022
Software Development

Avoiding Design by Committee

May 19, 2022
SAAS Applications

How AI Changes the Future of Sales and Marketing

May 19, 2022
SAAS Applications

Dynamics 365 CE Edit Filter Criteria Error

May 19, 2022
SAAS Applications

The Beginner’s Guide to SEO for Retailers

May 19, 2022

© 2022 Sass News Hubb All rights reserved.

Use of these names, logos, and brands does not imply endorsement unless specified. By using this site, you agree to the Privacy Policy

Navigate Site

  • Home
  • News
  • Software Engineering
  • Software Development
  • SAAS Applications
  • Contact Us

Newsletter Sign Up

No Result
View All Result
  • Home
  • News
  • Software Engineering
  • Software Development
  • SAAS Applications
  • Contact Us