Split the mass on two parts



  • Hello. How can the mass be broken into two parts at the right place if the element of the required index is repeated. For example, I need the last number in terms 45-23*996-25 (how do I smash the mass at the second minus)? Thank you.



  • Use it. https://learn.javascript.ru/array-methods#%D0%BC%D0%B5%D1%82%D0%BE%D0%B4-split for slaughter and https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/pop to take the last element.

    split - It's possible to turn the line into a mass, to break it down by the divider.

    pop removes the last element from the mass and returns its value.

    var test = '45-23*996-25';
    var last =  test.split('-').pop();
    

    console.log(last);


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2