@feelinglovelynow/loop-backwards
v1.0.3
Published
Loop an array backwards! Give loopBackwards() an array and a callback. Calback provides the current item, a splice function, and the current index. Splice function removes item from the array. If the splice function is called & the current item is a DOM e
Downloads
6
Maintainers
Readme
🕉 @feelinglovelynow/loop-backwards
💎 Install
pnpm add @feelinglovelynow/loop-backwards
🤓 Unit Tests
🙏 Description
Loop an array backwards! Give loopBackwards() an array and a callback. Calback provides the current item, a splice function, and the current index. Splice function removes item from the array. If the splice function is called & the current item is a DOM element the item is removed from the array & the item is removed from the DOM
💚 Example: Array of numbers
import loopBackwards from '@feelinglovelynow/loop-backwards'
loopBackwards(numbers, (number, splice, index) => {
if (number === 9 || index === 9) splice()
})
💛 Example: Array of objects
loopBackwards(items, ({ foo }, splice) => {
if (foo === 'bar') splice()
})
🧡 Example: Array of DOM elements
const domElements = document.querySelectorAll('div')
const arrayElements = Array.from(domElements)
loopBackwards(arrayElements, (element, splice) => {
if (element.getAttribute('foo') === 'bar') splice()
})
🎁 All Our Packages
- @feelinglovelynow/datetime-local: NPM ⋅ Github
- @feelinglovelynow/dgraph: NPM ⋅ Github
- @feelinglovelynow/env-write: NPM ⋅ Github
- @feelinglovelynow/get-form-entries: NPM ⋅ Github
- @feelinglovelynow/get-relative-time: NPM ⋅ Github
- @feelinglovelynow/global-style: NPM ⋅ Github
- @feelinglovelynow/jwt: NPM ⋅ Github
- @feelinglovelynow/loop-backwards: NPM ⋅ Github
- @feelinglovelynow/slug: NPM ⋅ Github
- @feelinglovelynow/svelte-catch: NPM ⋅ Github
- @feelinglovelynow/svelte-kv: NPM ⋅ Github
- @feelinglovelynow/svelte-loading-anchor: NPM ⋅ Github
- @feelinglovelynow/svelte-modal: NPM ⋅ Github
- @feelinglovelynow/svelte-turnstile: NPM ⋅ Github
- @feelinglovelynow/toast: NPM ⋅ Github