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

125
Views
display certain characters in string javascript

I receive from an api service this string

{\n "modelColor": ["000019000031262"]\n}"}

how can I display only the numbers : "000019000031262" in a console log or alert message using Javascript?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You could use String#match to extract the wanted part.

let str = '{\n "modelColor": ["000019000031262"]\n}"}';
let res = str.match(/\["(.*)"]/)[1]; // get first captured group
console.log(res);

about 4 years ago · Juan Pablo Isaza Report

0

You could try:

const str = `{\\n "modelColor": ["000019000031262"]\\n}"}`
const regex = /\[(.*)\]/gm;

console.log(regex.exec(str)[1])

But it seems most likely that the api is actually returning JSON (and that maybe you have clipped it). If so. Use JSON.parse to convert the string to an object

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!