score:1
Accepted answer
your problem is due to the value of audioduration is set only in callback and the console.log is used directly after onloadedmetadata so the console.log will run before the value is set. two ways to fix that, one way is to do console.log inside onloadmetadata. the other way is to return a promise and await for the result.
const audioduration = {}
const getduration = () => new promise(resolve => {
convertedaudio.onloadedmetadata = () => {
resolve(convertedaudio.duration);
}
})
getduration().then(l => { console.log(l); audioduration.length = l; })
score:0
try this
var audioduration = {};
convertedaudio.onloadedmetadata = () => {
if(convertedaudio.duration!=undefined){audioduration.length = convertedaudio.duration}
};
console.log (audioduration) // displays object {length: 25.547755}
console.log (audioduration.length) // displays idk, u see what it does since i can't replicated convertedaudio
Source: stackoverflow.com
Related Query
- How to access object provided by onloadedmetadata?
- How to access custom attributes from event object in React?
- How to access data attributes from event object
- how to access history object in new React Router v4
- how to pass object as params in Router.push() in nextjs and access that object in other component
- How to access the class name of a React object in this.props.children
- How to access Object array file into react component?
- How to access the history object in Jest
- How to access google.maps.Map object with react-google-maps
- Usign react-router-dom, how can I access browserHistory object from outside a React component?
- How to access object properties of 'key' object reactJS
- How to get access to `client` object anywhere in the app with Apollo Client?
- How to access object property by variable in Javascript
- How to get access to object which is in forEach Javascript
- How can I access JSON property of nested object inside object array
- How to access nested object in React js 0.13.3
- How to access a specific properties from a complex JSON array object in React.js
- How to access mobx object in webpack bundle(js) from external
- How can i access the history object inside of this promise call?
- How can I convert this object to an array and access values by key in React?
- How to access JSON object in React where the keys change
- ReactJS: How to access and update nested state object with dynamic key?
- ES6 Promises - Without using a deferred, how can I guarantee eventual access to an object instantiated during a React componentDidMount function?
- How can I access Electron's process object from my react app?
- How do I access nested JSON object data with React?
- How do I access a Map object using React Google Maps API?
- How to access nested array object in React
- Typescript: How to define conditional typescript props to access object in React?
- How to access nested props object in React TS?
- How to access item object outside "return" in react?
More Query from same tag
- Highcharts arearange draggableHigh and draggableLow not working
- Double Link Router in React
- How to reload a specific tag in reactJS
- My codes won't stop looping (Ionic React Firestore) (ReactJS)
- How do I limit possible inputs of String field in TextField component of Material-UI?
- React testing react-hook-form useForm
- React - arrow function syntax
- Getting error "Cannot update a component while rendering a different component". What is the correct way to achieve what I'm attempting?
- react-router-dom isnt working just render "/"
- ReactJS - CSS: setting trasitionProperty in style object does not work
- Warnings on update state of <select> based on state of previous <select> state
- When to scrollIntoView in React with an API call
- Can I run multiple React programs from bash and view them on the web?
- Component re-renders because of unused property in context
- Apache configuration for Reactjs application and Symfony Api on the same domain
- React State seems to be overwritten / setState seems not to work
- React function with multiple APIs calls
- How could I pass JSON object array result to my api URL? (In REACT)
- render component using document.getElementById
- Place label and input field on the same row, with padding
- Browser Crashes when uploading large files even after slicing on XMLHttpRequest (JavaScript/ReactJS)
- How to add a checking feature(for duplication) before adding new data to server react?
- How to update login data into state after changing pathname in reactjs
- not able to share state between two components in react
- ReactJS: How to hide/unhide images inside toggled list items
- React test with Enzyme, cannot read property 'route' of undefined
- How to Debug a React App in Visual Studio 2019 using the "Blank Node.js" Template
- Code Splitting ~ ReferenceError: System is not defined
- How to test if a React component contains another component with Tape and Enzyme?
- Invalid hook call expo