How to use simple js in expressions?


I want to shorten timestamp, which I receive out of previous node. For example i want to use .slice

How should I do it?
{{$json[“timestamp”].slice(-3)}} does not work.

Sorry for dumb question. I am very weak at js.

Hey @roge, welcome to the community!

.slice(-3) should work fine on strings, so your expression looks good to me:

Is there a chance your timestamp field isn’t a string? If so, you could try something like {{ $json["timestamp"].toString().slice(-3) }}:

1 Like

Thank you! This one worked well:
{{ $json[“timestamp”].toString().slice(-3) }}

1 Like

Excellent, glad to hear! Just for reference, here’s what .toString() is and does :slight_smile: