投稿時間:2022-09-19 07:10:52 RSSフィード2022-09-19 07:00 分まとめ(11件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
海外TECH DEV Community Everything you need to know about Javascript Arrays https://dev.to/smpnjn/everything-you-need-to-know-about-javascript-arrays-3po5 Everything you need to know about Javascript ArraysWith arrays there are usually a set number of specific things you want to achieve Below is a list of pretty much any action you would want to perform on an array and how to do it in Javascript If you have any more let me know in the comments below Find Index of an Element by ValueUse indexOf javascriptlet arr potato banana ravioli carrot Returns console log arr indexOf banana Returns since not foundconsole log arr indexOf beetroot Delete at IndexUse splice javascriptlet arr potato banana ravioli carrot Returns banana ravioli carrot since potato has index arr splice console log arr Delete at Index by ValueUse splice and indexOf javascriptlet arr potato banana ravioli carrot let itemIndex arr indexOf ravioli Returns potato banana carrot since ravioli has an index of arr splice itemIndex console log arr Get the last element of an arrayUse arr length javascriptlet arr potato banana ravioli carrot Returns carrotconsole log arr arr length Insert at IndexUse splice You can also read about inserting at an index in detail here javascriptlet arr potato banana ravioli carrot Inserts broccoli at position after deleting itemsarr splice broccoli Returns potato banana ravioli brccoli carrot console log arr Remove the last element of the arrayUse pop javascriptlet arr Returns console log arr pop Returns last element is removedconsole log arr Change all values of an array in the same wayUse map javascriptlet arr let newArr arr map function arrElement return arrElement ES version for modern browsers and NodeJSlet anotherVersion arr map el gt el Returns for bothconsole log newArr console log anotherVersion Turn a string map or set into an arrayUse Array from javascriptlet newSet new Set orange apple potato spinach let newMap new Map orange apple potato spinach let newString apple console log Array from newSet Returns orange apple potato spinach console log Array from newMap Returns orange apple potato spinach console log Array from newString Returns a p p l e Check if it is an arrayUse Array isArray javascriptlet arr orange apple potato spinach let obj myKey myValue console log Array isArray arr Returns trueconsole log Array isArray obj Returns false Check every element in an ArrayUse forEach javascriptlet arr orange apple potato spinach arr forEach function item console log item Returns each array item individually Merge two arraysUse or concat javascriptlet arr orange apple let arr potato spinach For legacy browsers ES Returns orange apple potato spinach let someArray arr concat object For modern Javascript ES NodeJS Returns orange apple potato spinach let someOtherArray arr arr Turn object names into arrayUse Object keys javascriptlet object name value name value name value Returns name name name let array Object keys object Turn object values into arraysUse Object values javascriptlet object name value name value name value Returns value value value let array Object values object Reverse an ArrayUse reverse javascriptlet arr potato banana carrot arr reverse Returns carrot banana potato console log arr Sum all Elements in an ArrayUse reduce javascriptlet arr For legacy browserslet getTotal arr reduce function accumulator currentNumber return accumulator currentNumber ES for modern browsers and NodeJSlet theTotal arr reduce accumulator currentNumber gt accumulator currentNumber Returns console log getTotal Add an Elements to the end of an arrayUse push javascriptlet arr banana potato arr push broccoli Returns banana potato broccoli console log arr Check if every element of an array passes a testUse every javascriptlet arr Will return true and console log great if arr every value gt value lt console log great 2022-09-18 21:56:08
海外TECH DEV Community Inserting an Item into an Array at a Specific Index in Javascript https://dev.to/smpnjn/inserting-an-item-into-an-array-at-a-specific-index-in-javascript-3g1c Inserting an Item into an Array at a Specific Index in JavascriptArrays are common data structures found in Javascript which typically look a bit like this let myArray some data here They act a lot like arrays found in other languages and are relatively easy to define Above we have an array consisting of three items which we ve stored within our array which is conveniently called myArray Sometimes though we want to insert a new item into an array at a specific point For example maybe we want to insert the word new after some This is known as inserting an item into an item at a specific index and today we re going to look at how you do that in Javascript Inserting an Item into an Array at a Specific IndexIn Javascript this turns out to be quite an easy operation to perform We use the splice method which is a simple function that takes arguments which also lets us delete items too Splice accepts arguments if you want to delete items from your array or if you want to add items splice startIndex deleteCount newItem newItem newItem Only the first option is required and the rest are optional So splice can take the following formats let myArray some data here myArray splice does nothingmyArray splice Deletes two items starting at index So some and data are deletedmyArray splice new Deletes zero items Adds new at index myArray splice is cool Deletes zero items Adds is and cool at index As you can see you can add an infinite number of new items to your array using this method It manpulates an array so the original array is changed by this function You don t have to delete any items using splice but you can if you want Either leaving the delete count as or empty will mean no items are deleted from your array Any data inserted in the third argument or any argument after the third argument is added to the array at the specified index Here is another example where we insert broccoli into an array at index let arr potato banana ravioli carrot Inserts broccoli at position after deleting itemsarr splice broccoli Returns potato banana ravioli brccoli carrot console log arr 2022-09-18 21:38:54
海外TECH DEV Community how to make an Indestructible button? https://dev.to/ymhaah/how-to-make-an-indestructible-button-3f2h how to make an Indestructible button Introductionthe button is a very simple component that is found on almost every website And the last thing you want when developing your site is to add another problem I think you already have enough layout and responsiveness problems And you don t want to add a button problem that doesn t work wellBut what if you have a button that works in all conditions work with flex Without any strange positioning issues and work with grid without any change in size It behaves as you expect it to behave It stays where you put it in the size you specified Smoothly interacts with the screen size and surrounding elements and the font size used If you just want to use this magic button without understanding how it works this is the code CodePenGitHubBut if you want to understand how it works choose which featuresyou want or even modify it complete the article with me where I will talk in detail about how I made this button frist HTML Nothing special here but I just want to make a few notes If you will use button element put the type button To tell the browser how this button behaves lt button type button class Button gt normal button lt button gt if you will use an Anchor element or a div For some reason put role button to specify to the browser what is the role of this link lt a href role button class Button gt a link button lt a gt Note If using role button instead of the semantic button or input type button elements you will need to make the element focusable and define event handlers for click and keydown events This includes handling the Enter and Space keypresses in order to process all forms of user input But if you do not know which one to use I recommend reading the following Anchors vs Buttons CSS For some reason whenever I use a library or open any good website I always try to see how they program their bottons So this code is a collection of many libraries and websites in addition to some of my thoughts And all of this while I try to follow basic design and accessibility rules You are free to change the sizes and the general shape of the button Because In general they did not affect the basic properties After all imagine that the indestructible button get destroyed due to a change in font size for example Some basics before we start I will use rem and em a lot and other units of measurement and I will explain simply during the article why I chose any one of them But if you want to know more I advise you to read this CSS Units ExplainedIn general I use CSS custom properties in my own code It gives me superpowers but I won t use them in this articleany feature I will use I will attach a link to it if you want to know more about it and of course I will explain to you why I used it specifically For credibility I will also attach the original source which I learned the trick fromWithout more talk let s start building the Indestructible button width amp heightthe trick here is not to specify a fixed size but rather to set limits for the largest and smallest size as the button size will depend mainly on the font size To determine the size we will follow the basic design rules for buttons To find out more I recommend reading this Button design for websites and mobile apps But for me after trying many values I found magic values that work with all designs Button min height rem max height em width min content max width min vw Let s talk about these values min height rem rem px From my point of view it is the smallest length any button should reach as shorter than that does not seem right and We will use rem To take into account this one person in a million who may change the font size settings of the browser max height em we will use em here Where the size is relative to the font size of the button and in general the way we will complete the button will make it not reach this length but it is placed as a limit to make sure there is no sudden stretching width min content In general you are not required to specify a width for the button and also where the button will work in any case without this feature but I use it as a safety valve to prevent anything unexpected I chose min content As it gives the least Problems and is more supported also it is dynamic with the width as it takes the smallest width that the element can have max width min vw This is also optional It might look complicated or overkill But let me explain You specify the largest width that the element can reach max width using the min To choose the smallest value between linked to the size of the parent element which may be half the screen for example vw linked to the screen size You do this to allow the element to expand if desired to either parent size or screen size Of course these sizes are usually linked to my CSS custom properties system display inline flex Now you determine how the button deals with the surrounding elements and with the elements inside Previously I used display Block then i use display inline Recently I was learning React and discovered MUI And as usual the first thing I did was look at how they did their button And found them using inline flex inline flexThe element behaves like an inline element and lays out its content according to the flexbox model Button display inline flex justify content center align items center text align center vertical align middle And using the magic of Flex We will center any items inside this button reference justify contentalign itemsand We will use properties like text align amp vertical align in general for To make sure an extra image or strange text is always in the middleFor the person who still uses an old browser for browser support In case flex doesn t work for some reason padding amp margin amp font sizeHere lies the magic that makes this button work in all cases and all sizes Button padding max em rem max em rem font size clamp rem rem vw rem Button not last child margin rem Of course this seems more overkill than the max width trick and it is but You will only copy this code once and it will work in all cases And of course I don t need to remind you that I usually use a mixture between CSS custom properties amp Sass mixin and function Which makes it easy as I enter only one number and all these numbers will be calculated for me padding max em rem max em rem The trick here is to use max Where if you notice that I use the same value once with rem and once with em but why The point of max It is to choose which value is greater Usually em will be bigger Where if we assume that the font size of the button is pxem px and rem px Follow the default browser sizeSo why do we do this In general when using a small font size such as pxif you use just em The button dimensions will be too narrow Since it is related to the font sizeem px rem px Still at the default text sizeAnd then rem will be the biggest In short you use this trick to define the minimum space inside the button and at the same time it allows you to stretch with the font size And of course the width amp height tricks will help a lot but it can be changed according to your needs so I rely on this trick mainly font size clamp rem rem vw rem Honestly I cannot explain to you how to choose these values here as I will need another article But in short using clamp Allows you to use a font that is responsive to your screen size with a minimum of rem and a maximum of rem for Example To make it easier you can use a font size clamp calculatorI strongly advise you to read these articles as they will benefit you in web dev in general Linearly Scale font size with CSS clamp Creating a Fluid Type Scale with CSS ClampModern Fluid Typography Using CSS ClampNote There are many other ways you can achieve a responsive font size But I will dedicate an entire article to it in the future There is nothing special with margin we just use not To determine that we do not want to target the last child Remember to change the direction of margin in phone mode media screen and max width em Button width Button not last child margin rem Extra features Button overflow hidden white space nowrap cursor pointer user select none appearance button overflow hidden To prevent anything from coming out outside the button white space nowrap Prevent text from going to more than one line Although I am sure that we have built a button that does not need safety features like these but the precaution is necessarycursor pointer The cursor is a pointer that indicates a link Typically an image of a pointing hand user select none make The text of the element and its sub elements is not selectable user select is not supported by Safari Safari on iOS This is an optional feature where if the button contains important text you may allow it appearance button The appearance CSS property is used to control native appearance of UI controls that are based on operating system s theme appearance is not supported by Safari on iOS lt hover amp focus Button box shadow em hsl em rgba transition box shadow ms cubic bezier Button active Button hover opacity Button focus visible box shadow em hsl em rgba Button focus outline none Nothing special I just determined how the button behaves in different situationsIf you want to know more about the focus visible trick I advise you to watch the video of the king of css about it Use this instead of focus most of the time ConclusionIn general this code is not fixed but for my it is always present at the beginning of every project and all I need is a few modifications to work with any site And believe me when you use this code with CSS custom properties amp Sass You will not need to touch this code again in your life as it just works Although I doubt that anyone will read this article but if you want to know how my CSS custom properties amp Sass System Tell me in the commentsAnd in the end this is the complete code for the example used in the article a button font inherit Button max height em min height rem width min content max width min vw display inline flex justify content center align items center text align center vertical align middle overflow hidden appearance button user select none text transform capitalize white space nowrap text decoration none cursor pointer padding max em rem max em rem font size clamp rem rem vw rem font weight background color hsl color hsl border px solid hsl outline none border radius px box shadow em hsl em rgba transition box shadow ms cubic bezier Button img max width clamp rem rem vw rem margin left rem Button not last child margin rem Button active Button hover opacity Button focus visible box shadow em hsl em rgba Button focus outline none media screen and max width em Button width Button not last child margin rem I hope you liked the article I feel like I took a little long to talk about something that isn t a big deal But I felt that I should share this code with you since I am a human being who can make mistakes or to be less knowledgeable than you if you find any mistake or have any suggestion feel free to comment 2022-09-18 21:15:56
海外TECH CodeProject Latest Articles Get AWS Web ACL with PowerShell Core https://www.codeproject.com/Articles/5342481/Get-AWS-Web-ACL-with-PowerShell-Core powershell 2022-09-18 21:42:00
ニュース BBC News - Home 'We were moved beyond measure' - King comforted by support https://www.bbc.co.uk/news/uk-62948816?at_medium=RSS&at_campaign=KARANGA measure 2022-09-18 21:33:34
ニュース BBC News - Home George and Charlotte to join Westminster Abbey mourners https://www.bbc.co.uk/news/uk-62948871?at_medium=RSS&at_campaign=KARANGA prince 2022-09-18 21:30:06
ニュース BBC News - Home Ukraine war: Russian pop megastar Alla Pugacheva condemns conflict https://www.bbc.co.uk/news/world-europe-62948146?at_medium=RSS&at_campaign=KARANGA russia 2022-09-18 21:52:00
ニュース BBC News - Home Queen Elizabeth's funeral: Order of service https://www.bbc.co.uk/news/uk-62948934?at_medium=RSS&at_campaign=KARANGA buckingham 2022-09-18 21:34:05
北海道 北海道新聞 世界レスリングで樋口が優勝 男子フリースタイル61キロ級 https://www.hokkaido-np.co.jp/article/733119/ 世界選手権 2022-09-19 06:09:00
ビジネス 東洋経済オンライン 新観光列車「ふたつ星」が握る西九州新幹線の命運 報道公開で明かされた最も重要な要素とは何か | 特急・観光列車 | 東洋経済オンライン https://toyokeizai.net/articles/-/619101?utm_source=rss&utm_medium=http&utm_campaign=link_back 観光列車 2022-09-19 06:30:00
ビジネス プレジデントオンライン 手法はトランプそっくり、しかも若くて賢い…イーロン・マスクが乗り換えた次期大統領候補のすごい勢い - ライバルの人気沸騰に焦るトランプ前大統領 https://president.jp/articles/-/61598 前大統領 2022-09-19 07:00:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)