1
const [top, bottom, left, right] = [txtStyle.getPropertyValue('top'),
          txtStyle.getPropertyValue('bottom'),
          txtStyle.getPropertyValue('left'),
          txtStyle.getPropertyValue('right')];

Values are assigned as "24px" etc. But I want to assign it as 24 (int). Which is the best way to do it?

3
  • 1
    parseInt("24px") === 24. Is that the solution you wanted? Commented Nov 8, 2020 at 13:52
  • 1
    assign it as 24, seems parseInt("24px") would work Commented Nov 8, 2020 at 13:57
  • parseFloat() did the work. Thanks. Commented Nov 8, 2020 at 13:58

1 Answer 1

2

You can use parseInt

const [top, bottom, left, right] = [parseInt(txtStyle.getPropertyValue('top')),
  parseInt(txtStyle.getPropertyValue('bottom')),
  parseInt(txtStyle.getPropertyValue('left')),
  parseInt(txtStyle.getPropertyValue('right'))
];

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.