replaceAll() is not a function

Hello!
I’m using the raycaster to intersect loaded GLTFs and get their and their parents’ names to change the context of an HTML text later on. When I do this:

INTERSECTED = intersects[0].object.parent;
              
posNumbString = INTERSECTED.parent.name.toString();
posNumbChange = posNumbString.replaceAll('-', 'i');

posNumb.textContent = posNumbChange;

I get this error: ‘TypeError: posNumbString.replaceAll is not a function’

Can somebody help?

replaceAll() does not exist in JavaScript. Use this approach instead:

posNumbChange = posNumbString.replace(/-/g, 'i');
3 Likes

Thank you! :slight_smile:

As of Firefox 77, there is support for replaceAll with JavaScript:

1 Like

Chrome 85 also landed support for replaceAll:

2 Likes

I’ve tried both replaceAll() and replace(). However, I’m getting the following error:
TypeError: t.push(…).replaceAll is not a function [replaceAll()]
TypeError: t.push(…).replace is not a function [replace()]

Could you please help me how to fix it? Thanks