read a number, such as 521
change this number to 0521
but put it into four div separately, how to realize it?
let n = 521; //
n = (n*1).toString().padLeft(4,'0');
for(let v of n){
let dom = document.createElement('div');
dom.innerText = v;
//dom appendTodom
}
-
In the chained promise function, how to determine which promise threw the error
I need to implement in a chained promise function, any function error in the middle terminates the program, and can catch the error function, and then perform different operations according to different error functions. How can the following code be imp...
Feb.26,2021 -
How to use Generator to implement a chain dependent function?
how do I use generator to achieve the following functions? function f1(){ return new Promise((resolve,reject) =>{ setTimeout(() =>{ resolve(1); },1000) }) } function f2(valu...
Feb.27,2021 -
This problem of js Arrow function
I don t understand why this is window in this broken code. Thank you for your understanding. Thank you. var o = { fn:() => { console.log(this) } } o.fn() ...
Feb.28,2021 -
How does js implement a general regular validation form method (minimum code)
1. How to implement a general regular validation form with the least amount of code = project, 1. Login has two input (verify mailbox, password 10 digits + letters) 2. input () both forms are displayed after input loses focus (correct or w...
Mar.01,2021 -
I want to use some of the constants defined in state to assign default values to the drop-down box and v-model this variable in the data of the component, what should I do?
I m going to assign the default value of 1 to the value of the drop-down box and bind this variable; <select v-model= selectValue >< select> but just let data(){ return{ selectValue:1 } } this type of writing is not readable, so I ...
Mar.03,2021 -
Convert js to timestamp
converts the current time to a timestamp and saves it to localStorage. uses another time to generate a timestamp to determine whether the interval between the two is greater than one month. or not switch to a timestamp, as long as you can determine t...
Mar.03,2021 -
What is the most elegant way to implement an array of ES6 objects based on a property?
A solution that conforms to the meaning of the question function unique(arr) { const res = new Map(); return arr.filter((a) => !res.has(a) && res.set(a, 1)) } because map key is unique, you can change the an in res.has (a) to whate...
Mar.03,2021 -
How to understand closures
1. Use var: var a = []; for (var i = 0; i < 10; iPP) { a[i] = function () { console.log(i); }; } a[6](); 10 2. Use let var a = []; for (let i = 0; i < 10; iPP) { a[i] = function () { console.log(i); }; } a[6](); 6 quest...
Mar.03,2021 -
Es6, removes the contents of one array from another array
my code has bug, and then I checked to write = = as = . A [1,2,3,4,5,6,7] B [2,3,4] after deletion A [1,5,6,7] this.selectRightTableData.forEach(item => { this.rightTableData.splice(this.rightTableData.findIndex(v => v.id = item.id...
Mar.03,2021 -
How to handle asynchronous queuing in dva
* deleteDetails({payload}, {call, put}) { const result = yield call(deleteDetails, {payload}); if (result.code !== 200) { throw result.msg; } else { Toast.success(result.msg, 1); yield put(routerRedux.goBack(...
Mar.04,2021 -
How does es6's Set customize the de-repetition rules? How can an array of objects be duplicated according to a column property?
for example, duplicates according to the name attribute in the an array element. is this the simplest way? function unique(arr) { const res = new Map(); return arr.filter((a) => !res.has(a.name) && res.set(a.name, 1)) } reference...
Mar.04,2021 -
Deconstruction of ES6- function
The deconstruction of the function does not quite understand the red arrows in this. Why undefined? Is it not true that when let {XMagi y} = {XRO 0PersonyGl} , x can output equal to 0LI YQ 1, although XMagi y is a pattern and the assignment is assig...
Mar.04,2021 -
JS rendering output string concatenation html should not have a comma
navMenuData.sort(sortID).map((item) => { let option; if (item.options) { let optionJSON = JSON.parse(item.options) option = optionJSON.map((item) => { return `<a href="-sharp">${item.name}< a>` ...
Mar.05,2021 -
What is the most elegant way for js to add another array to the end of the array?
is there a method like push, but instead of inserting an element into an array, add another array similar to java s addAll method all I know so far is concat, but he returns the new array instead of making changes on the original array, ...
Mar.06,2021 -
The problem of clock function in Generator function in ES6
var clock = function*() { while (true) { console.log( Tick! ); yield; console.log( Tock! ); yield; } }; you can see that the state machine implemented by the Generator function does not need to set initial variables or switch ...
Mar.10,2021 -
It doesn't matter how gracefully es6 judges that the values contained in two arrays are exactly the same.
this is what I do now. Is there a better way? let flag = true const listA = [1, 2, 3] const listB = [2, 3, 4] if (listA.length !== listB.length) { flag = false } else { listA.forEach(item => { if (listB.indexOf(it...
Mar.10,2021 -
Solve the problem of array processing?
let keys = [ a , b ] let vals = [ [111, 222], [333, 444] ] expected result: [{a:111,b:222},{a:333,b:444}] ...
Mar.14,2021 -
Js array operation
var str = "abc-a,add-a,ccc-b,ccc-d,abc-a,abc-b,abc-f,tbg-g "; convert the above string to the following array form: var arr = [ {"name" : "abc", "nameIdx":[{"site" : "a"}]}, {"name"...
Mar.14,2021 -
How to transfer parameters asynchronously by js?
I have several asynchronous function operations, but I want these asynchronous operations to be performed sequentially, I want to use queues, and each function needs to pass parameters. I think of the middleware of koa2, but how do I implement it? Or is ...
Mar.17,2021 -
About the understanding of the default values of es6 function parameters?
var x = 1; function foo(x, y = function() { x = 2; }) { var x = 3; y(); console.log(x); } foo() 3 x 1 the above is the penultimate example of the scope of the function in the book introduction to es6 written by teacher Ruan Yifeng . Teache...
Mar.18,2021
- False
- Django, Why does the system automatically generate an empty session? every time the request is made?
- Use python to convert dict1 to dict2, in the example. I tried for a long time but couldn't find a solution.
- How to self-start the php-fpm service when building a LNMP environment with docker?
- Can an array in react state be bound to a dom state using an element in the array?
- Wechat browser version 6.6.5 cannot prevent the springback of pull-up and drop-down to the top under ios system.
- In express+hbs, how do you define the routed data as a variable on the page?
- How to use symbol reference of Iconfont in dva
- How to elegantly add data to JSON objects?
- Using node to build video streaming server
- The proportional width of the echarts graph is inconsistent.
- React uses axios to call the background data. After success, how to jump to the page based on the returned value?
- I don't understand what a linux command means. Please explain it.
- Vue introduces multiple components in vue-router by nesting named views, and does not refresh the same reference in other pages.
- Running nodejs reports fewer errors ")"
- Can swiper add transition time to the first one loaded at the beginning?
- Vue does not click the submit button. Submit is triggered when input is typed. I don't know why.
- How to format html and css code when vscode is saved (with eslint plug-in)
- Wechat's browser obtains the user's mobile phone model.
- Idea to stop tomcat needs to be pressed twice