Checking microphone volume in Javascript

A slightly more detailed answer after having to work it out myself feel may help others looking here. This following code will log out a number of approx 0 to 100 based on the microphone volume. navigator.mediaDevices.getUserMedia({ audio: true, video: true }) .then(function(stream) { const audioContext = new AudioContext(); const analyser = audioContext.createAnalyser(); const microphone … Read more

background-image in react component

You have to import the image as the following, using the relative path. import React from ‘react’; import Paper from ‘material-ui/Paper’; import IconButton from ‘material-ui/IconButton’; import ActionHome from ‘material-ui/svg-icons/action/home’; import Image from ‘../img/main.jpg’; // Import using relative path const styles = { paperContainer: { backgroundImage: `url(${Image})` } }; export default class Home extends React.Component{ render(){ … Read more

Changing the order of the Object keys….

If you create a new object from the first object (as the current accepted answer suggests) you will always need to know all of the properties in your object (a maintenance nightmare). Use Object.assign() instead. *This works in modern browsers — not in IE or Edge <12. const addObjectResponse = { ‘DateTimeTaken’: ‘/Date(1301494335000-0400)/’, ‘Weight’: 100909.090909091, … Read more

WooCommerce: trigger event after change of variation

In case anyone stumbles across this in the future: WooCommerce provides triggers throughout the add-to-cart-variation.js which allows you to hook into change events for the website. You can find all of them available in that file, but one which will likely help most in this case can be used as such $( “.variations_form” ).on( “woocommerce_variation_select_change”, … Read more

Using JavaScript what’s the quickest way to recursively remove properties and values from an object?

A simple self-calling function can do it. function removeMeta(obj) { for(prop in obj) { if (prop === ‘$meta’) delete obj[prop]; else if (typeof obj[prop] === ‘object’) removeMeta(obj[prop]); } } var myObj = { “part_one”: { “name”: “My Name”, “something”: “123”, “$meta”: { “test”: “test123” } }, “part_two”: [ { “name”: “name”, “dob”: “dob”, “$meta”: { … Read more