Skip to content

Instantly share code, notes, and snippets.

@CarlOlson
Created September 20, 2023 09:14
Show Gist options
  • Save CarlOlson/45d15dde94b5bf1fe650b529e036477f to your computer and use it in GitHub Desktop.
Save CarlOlson/45d15dde94b5bf1fe650b529e036477f to your computer and use it in GitHub Desktop.
let input = "{\"id\": 1, \"cell\":{\"id\":\"12345678-etc\"}}";
let obj = JSON.parse(input)
console.log(obj.cell.id); // 12345678-etc
let match = obj.cell.id.match(/^\d*/);
let id = match[0];
console.log(id) // 12345678
console.log(typeof id) // string
id = parseFloat(id);
console.log(id) // 12345678
console.log(typeof id) // number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment