0

Having trouble figuring out how to get the correct numbers to set some variables when i read API item

Here is item in API - h2hwlt="15‑12‑3"

I need to get the numbers 15 , 12 and 3 to set as variables

var wins = parseInt(response.leagueStandings.franchise[i].h2hwlt); // i want only # '15' here
var losses = parseInt(response.leagueStandings.franchise[i].h2hwlt); // i want only # '12' here
var ties = parseInt(response.leagueStandings.franchise[i].h2hwlt); // i want only # '3' here
Phil
  • 157,677
  • 23
  • 242
  • 245
MShack
  • 642
  • 1
  • 14
  • 33
  • 2
    Split it by `‑` (which is non breaking dash btw) – IT goldman Aug 04 '22 at 23:40
  • 2
    ... `const [wins, losses, ties] = h2hwlt.split('‑')` – Phil Aug 04 '22 at 23:41
  • unfortunately being a novice I'm not really understanding without some visual code – MShack Aug 04 '22 at 23:41
  • @MShack you can use `const [wins, losses, ties] = h2hwlt.split('‑').map(parseInt)` instead of your code. The key here is `split` function though. Learn about it and try to implement one on your own - if you don't want to be novice. – IT goldman Aug 05 '22 at 09:35

0 Answers0