# \`substr\` is deprecated

**URL:** <https://discourse.nodered.org/t/substr-is-deprecated/65777>\
**Category:** General\
**Created:** [29 July 2022 10:46 UTC](https://discourse.nodered.org/t/substr-is-deprecated/65777 "2022-07-29T10:46:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [29 July 2022 10:46 UTC](https://discourse.nodered.org/t/substr-is-deprecated/65777/1 "2022-07-29T10:46:01Z")

</div>

Hi,  
Help me understand please ...

I have a function and variable var\_push is a string value "06.10"; the function work fine...

![img1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b101cbdbbadacba388a82fbb831b9950ca63fe25.png)

If I change the function (image)

![img2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/aca489cfe5550382c7d1b3cf8aa532c242ad5ccf.png)

I have a alert? warning? (image)

![img3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bcdef6466de52822c6c19958b3ee9fdc037d0fd4.png)

Why? Where is the problem?  
(I change const to let but this is not the problem of course)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [29 July 2022 10:48 UTC](https://discourse.nodered.org/t/substr-is-deprecated/65777/2 "2022-07-29T10:48:52Z")

</div>

LMGTFY - [Javascript Tips: slice, substr, substring | by Gustavo Alves | Medium](https://medium.com/@gustavoalvescc/javascript-tips-slice-substr-substring-7fb052a45802#:~:text=substr(%E2%80%A6)%20is%20not%20strictly,the%20substring()%20method%20instead).

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 July 2022 10:54 UTC](https://discourse.nodered.org/t/substr-is-deprecated/65777/3 "2022-07-29T10:54:59Z")

</div>

> [@Giamma](#):
>
> I have a function and variable var\_push is a string value "06.10"; the function work fine

Entering `let x = flow.get('var_push')` means the editor has no idea what `x` is.  
Lets say for arguments sake x is now an instance of `MyLegacyString` and `MyLegacyString`has a prototype function named `substr` - this is perfectly valid as far as the editor knows.

Entering `let x = "06:10"` makes the editor realise that `x` is a native `string`. And as @dceejay points out...

> `String.prototype.substr(…)` is not strictly deprecated (as in “removed from the Web standards”), it is considered a legacy function and should be avoided when possible. It is not part of the core JavaScript language and may be removed in the future. If at all possible, use the `substring()` method instead

In short, use `substring` if you care - or use `substr` if you dont.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 July 2022 11:00 UTC](https://discourse.nodered.org/t/substr-is-deprecated/65777/4 "2022-07-29T11:00:29Z")

</div>

There is no problem the editor is warning that substr is depreciated and would be best to use substring or slice. The warning is there so you know that substr is depreciated. The substr will still work as it is there for legacy code, so older scripts still work. You can move to substring or slice, as one day substr may stop working, if removed from JS as a legacy function/method. [String.prototype.substr() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) for more info

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [29 July 2022 11:08 UTC](https://discourse.nodered.org/t/substr-is-deprecated/65777/6 "2022-07-29T11:08:41Z")

</div>

@dceejay  
@Steve-Mcl  
@E1cid

Thank you very much .....

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 September 2022 11:09 UTC](https://discourse.nodered.org/t/substr-is-deprecated/65777/7 "2022-09-27T11:09:20Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
