简体   繁体   English

为计算器的删除按钮编写 function 的适当方法是什么?

[英]what are the appropriate way of writing a function for a delete button for a calculator?

I am a react beginner, have been trying to write a code inside deletehandler function wish was assign to delete button, whereby if the button is clicked.我是一个反应初学者,一直在尝试在 deletehandler function 中编写代码,希望将其分配给删除按钮,如果单击该按钮。 one or more value on the calculator screen should be erase or removed.计算器屏幕上的一个或多个值应被擦除或删除。

How can I get this done?我怎样才能完成这项工作?

This is my code so far;到目前为止,这是我的代码;

const deleteClickHandler = () => {常量 deleteClickHandler = () => {

 let num = calc.num ? toLocaleString(removeSpaces(-calc.num)) : 0;
 let res = calc.res ? toLocaleString(removeSpaces(-calc.res)) : 0;

setCalc({
  ...calc,
   num: (num /= splice(0, -1)),
   res: (res /= splice(0, -1)),
   sign: "",
 });
}

If you are removing the last index in an array, for instance, you can use pop()例如,如果要删除数组中的最后一个索引,则可以使用 pop()

let numbers = [71, 6, 3 , 45, 5]; 
numbers.pop();

you can also apply this kind of approach with your res KEY你也可以用你的 res KEY 应用这种方法

// [71, 6, 3, 45]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM