Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Looking to remove any value after :->

I am looking to remove any value after ':->' in JavaScript For example if 'Packet:->3', I would like to store "Packet:->" in the variable so I can use it before the if statement seen below. Pretty much I am looking to remove any digits after '>'

I was trying the below, but did not have much luck.

NTEremoved = NTE.indexOf(':->');

What would be the best way of doing this?

if(NTE == 'Packet:->' || NTE == 'Serving:->' || NTE == 'Can/Carton/Bottle:->'){

} 
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

String split.

const testStr1 = "Packet:->3";
const testStr2 = "BlahBlahBlah278:->Hello hello this is cool";
const result1 = testStr1.split(":->")[0] + ":->"; // split "splits" the string into an array based on the delimiter ":->"; the second part would be 3
const result2 = testStr2.split(":->")[0] + ":->";
console.log(result1);
console.log(result2);

Docs.

about 4 years ago · Juan Pablo Isaza Report

0

I would do something like this, to take care also of edge cases (assuming you don't care about what is coming after the first :->:

let texts = ["Packet:->11", "Cat:->22", "Packet:->:->:->44"];

for (let text of texts) {
  console.log(text.replace(/(:->).*$/, "$1"))
}

about 4 years ago · Juan Pablo Isaza Report

0

Since you have mentioned you have tries to use indexOf before but fail to do that, I will provide you a way using a combination of indexOf and String.slice

let string = "Serving:->3"
//Indexof return the first index of an element so you have to add 3 (the length of ":->"
let newstring = string.slice(0,string.indexOf(":->")+3)

console.log(newstring)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!