Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the JS streamlined code?

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what JS streamlined code". In daily operation, I believe many people have doubts about which JS streamlined code. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what JS streamlined code?" Next, please follow the editor to study!

calendar

Create an array for the past seven days, and if you replace the minus sign with a plus sign in the code, you will get a collection of arrays for the next seven days.

/ / create an array of the past seven days [. Array (7). Keys ()] .map (days = > new Date (Date.now ()-86400000 * days))

Generate random ID

The function of creating ID is often used in prototype design, but I see people using it in actual projects, which is actually quite unsafe.

/ / generate a random alphanumeric string of length 11 Math.random () .toString (36) .substring (2); / / hg7znok52x

Get the query parameters of URL

Gets the query parameters in URL.

/ / get the query parameters of URL: Q = {}; location.search.replace (/ ([^? & =] +) = ([^ &] +) / g, (_, kheroin v) = > Q [k] = v); Q

Get local time

Through a pile of js code, you can get the local time

/ / create local time document.body [XSS _ clean] = new Date (). ToLocaleString (). Slice (10jue 19) ">

Array confusion

Used to randomly change the order of elements in an array

/ / randomly change the order of the elements of the array, confusing the array (arr) = > arr.slice (). Sort () = > Math.random ()-0.5) / * let a = (arr) = > arr.slice (). Sort () = > Math.random ()-0.5) let b = a ([1m (b)]) console.log (b) * /

Generate random colors

Used to generate random colors

/ / generate random hexadecimal codes such as:'# c618b2''#'+ Math.floor (Math.random () * 0xffffff) .toString (16) .padEnd (6,'0')

Do you know the result of this code running?

For [. "``1234567890-=~~QWERTYUIOP []\ ~ ASDFGHJKL;'~~ZXCVBNM,./~"] .map (x = > (ofex = `/ ${b='_'.repeat (wrapx))

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report