Truncating a String with JQuery

For some reason Drupal's views + services + rest output doesn't truncate the body text even when it's set to trim. I couldn't find a quick fix or anyone else having the same problem so I found a Stackoverflow page with a convienent jQuery code snippet to truncate. Changed the substring number from characters to 450 characters and this is the code I ended up with:

1
2
var node_body = data[key].node_data_field_body_field_body_value;
node_body = $.trim(node_body).substring(0, 450).split(" ").slice(0, -1).join(" ") + "...";

Worked great!

Built with Hugo
Theme Stack designed by Jimmy