Indian money format function
Showing posts with label JScript. Show all posts
Showing posts with label JScript. Show all posts
Tuesday, January 5, 2021
Tuesday, October 22, 2019
8 Must Know JavaScript Array Methods
Working with arrays in JavaScript used to be a pain with barely any support for complex array operations. Fast forward to today, though, and there are tons of amazing JavaScript array methods available to us. In this video I will be covering the 8 most important array methods in JavaScript.
const items =[
{ name: 'Bike', price:100},
{ name: 'TV', price:200},
{ name: 'Album', price:10},
{ name: 'Book', price:5},
{ name: 'Phone', price:500},
{ name: 'Computer', price:1000},
{ name: 'Keyboard', price:25}
]
// create another array with filtered items
const filteredItems = items.filter((item) => {
return item.price <= 100
})
console.log(filteredItems);
// get element and create another array
const itemNames = items.map((item) => {
return item.name
});
console.log(itemNames)
//find element in array
const foundItem = items.find((item) =>{
return item.name === 'Album'
})
console.log(foundItem)
//forEach
items.forEach((item) =>{
console.log(item.price)
})
// some -- return true if found
const hasInExpensiveItem = items.some((item) =>{
return item.price <= 100
})
console.log(hasInExpensiveItem)
// calculate with variable initiate as 0
const total = items.reduce((currentTotal, item){
return item.price + currentTotal
},0) // 0 is the initial value of CurrentTotal
console.log(total)
// include -- if item present in array return true.. this work fine with simple array...
const items =[1, 2, 3, 4, 5]
const includesTwo = items.includes(2)
console.log (includesTwo) // return True..
const includesTwo = items.includes(6)
console.log (includesTwo) // return false..
// distinct from array
var distinct = (value, index, self) =>{
return self.indexOf(value) === index;
}
var years = [2016, 2017, 2017, 2020, 2016, 2019]
var distinctYears = years.filter(distinct)
output : [2016, 2017, 2020, 2019]
Thanks to Web Dev Simplified and codeburst
const items =[
{ name: 'Bike', price:100},
{ name: 'TV', price:200},
{ name: 'Album', price:10},
{ name: 'Book', price:5},
{ name: 'Phone', price:500},
{ name: 'Computer', price:1000},
{ name: 'Keyboard', price:25}
]
// create another array with filtered items
const filteredItems = items.filter((item) => {
return item.price <= 100
})
console.log(filteredItems);
// get element and create another array
const itemNames = items.map((item) => {
return item.name
});
console.log(itemNames)
//find element in array
const foundItem = items.find((item) =>{
return item.name === 'Album'
})
console.log(foundItem)
//forEach
items.forEach((item) =>{
console.log(item.price)
})
// some -- return true if found
const hasInExpensiveItem = items.some((item) =>{
return item.price <= 100
})
console.log(hasInExpensiveItem)
// calculate with variable initiate as 0
const total = items.reduce((currentTotal, item){
return item.price + currentTotal
},0) // 0 is the initial value of CurrentTotal
console.log(total)
// include -- if item present in array return true.. this work fine with simple array...
const items =[1, 2, 3, 4, 5]
const includesTwo = items.includes(2)
console.log (includesTwo) // return True..
const includesTwo = items.includes(6)
console.log (includesTwo) // return false..
// distinct from array
var distinct = (value, index, self) =>{
return self.indexOf(value) === index;
}
var years = [2016, 2017, 2017, 2020, 2016, 2019]
var distinctYears = years.filter(distinct)
output : [2016, 2017, 2020, 2019]
Thanks to Web Dev Simplified and codeburst
Tuesday, June 11, 2019
Integer value with leading zero using JavaScript
prefix_zero(10,4) // output 0010
function prefix_zero(num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
}
Tuesday, June 19, 2018
Remove duplicate through JQuery
test1
test2
test1
test2
var seen = {};
$('table tr').each(function() {
var txt = $(this).text();
if (seen[txt])
$(this).remove();
else
seen[txt] = true;
});
Thursday, March 29, 2018
Only Numeric with Single Decimal - JavaScript
//Keypress event on a Class
$('.onlyNumeric').on('keypress', function(e) {
return isNumber(event, this);
});
//Function to validate Number, Decimal and Negative sign
function isNumber(evt, element) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (
(charCode != 46 || $(element).val().indexOf('.') != -1) &&
(charCode < 48 || charCode > 57))
return false;
return true;
}
Friday, March 4, 2011
Some funny JScripts
(1) Copy and paste the java script code to the address bar of your browser and Press Enter. Watch your window's "shaking it" !!!
javascript:a=0;x=0;y=0;setInterval("a+=.01;x=Math.cos(a*3)*200;y=Math.sin(a*2)*2;moveBy(x,y)",2);void(0)
(2) Float the Body of your webpage.
javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName("body");DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}setInterval('A()',5); void(0);
(3) Start Editing any web Page... and have some Fun !!!
javascript:document.body.contentEditable='true'; document.designMode='on'; void(0)
Subscribe to:
Posts (Atom)
var seen = {};
$('table tr').each(function() {
var txt = $(this).text();
if (seen[txt])
$(this).remove();
else
seen[txt] = true;
});
Thursday, March 29, 2018
Only Numeric with Single Decimal - JavaScript
//Keypress event on a Class
$('.onlyNumeric').on('keypress', function(e) {
return isNumber(event, this);
});
//Function to validate Number, Decimal and Negative sign
function isNumber(evt, element) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (
(charCode != 46 || $(element).val().indexOf('.') != -1) &&
(charCode < 48 || charCode > 57))
return false;
return true;
}
Friday, March 4, 2011
Some funny JScripts
(1) Copy and paste the java script code to the address bar of your browser and Press Enter. Watch your window's "shaking it" !!!
javascript:a=0;x=0;y=0;setInterval("a+=.01;x=Math.cos(a*3)*200;
y=Math.sin(a*2)*2;moveBy(x,y)",2);void(0)
(2) Float the Body of your webpage.
javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName("body");DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}setInterval('A()',5); void(0);
(3) Start Editing any web Page... and have some Fun !!!
javascript:document.body.contentEditable='true'; document.designMode='on'; void(0)
Subscribe to:
Posts (Atom)